Shell script seems to skip over commands while executing - linux

I'm trying to create a process where, on detecting my smart watch connecting to it, my Raspberry Pi (4b 2GB) would automatically download new podcast episodes then transfer them to my watch. I have managed to create a udev rule to execute a shell script on detection, but it seems to skip the most vital commands (upodder and mtp-sendfile)? Code below:
#!/usr/bin/env sh
PATH=$PATH:/home/pi/.local/bin:/home/pi/.vscode-server/bin/485c41f9460bdb830c4da12c102daff275415b53/bin:/home/pi/.local/bin:/home/pi/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
echo "Watch connected at $(date)" >>/tmp/scripts.log
# Download new podcasts
/home/pi/.local/bin/upodder
# Transfer podcasts
/usr/bin/mtp-sendfile ~/Downloads/podcasts/WFH_Beckham_Sweden_and_Bango.mp3 /Podcasts
echo "Upodder should've run by now">>/tmp/scripts.log
I know that the file runs because /tmp/scripts.log is created and updated, but the podcasts aren't downloaded or transferred. upodder is a linux podcast downloader and mtp-tools is a way to transfer files through MTP. It's pretty clear that the issue is with these two commands but I can't seem to find the solution anywhere. Thanks in advance.
edit: Iruvar suggestion has helped but now I get the error:
Unable to determine user's home directory, MTPZ disabled.
Device 0 (VID=091e and PID=4c05) is UNKNOWN in libmtp v1.1.16.
Please report this VID/PID and the device model to the libmtp development team
~/Downloads/podcasts/WFH_Beckham_Sweden_and_Bango.mp3: stat: No such file or directory
Seems the issue is with the home directory.

Related

Strange Behavior with clamd scan function

I have a simple python3 script running on ubuntu server 20.04 that tries to call clamd (clamav-daemon process) library to scan a file. The scan ping() and version() function all work correctly. However when I actually do a test write and scan, i get the following error:
{'/filedrop/test.doc': ('ERROR', "Can't open file or directory")}
This is the code that I used to call the test write and scan, and this is all standard sample from the clamd website:
open('/filedrop/test.doc','wb').write(clamd.EICAR)
print(cd.scan('/filedrop/test.doc'))
After the code is run, i get the following string in the test file which indicates that the python3 script was able to successfully write to the file, yet i keep getting the error that the file can't be opened when i use the clamd scan function.
This is the string that was written to the file:
X5O!P%#AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
I am also able to run clamscan from command line on the folder and it successfully scans the files as well.
I'm running as root user while the service is using clamav:clamav.
I did give read/write permission to the folder and the files to "other users", and also indicated by the fact that the file could be written by the python script.
I believe the solution to the problem here is that AppArmour is blocking clamd for that particular directory. I would look at the AppArmour profile for clamd. It should be called something like /etc/apparmor.d/clamav or similar. You can adjust that profile or alternatively disable it (according to Ubuntu):
sudo ln -s /etc/apparmor.d/profile.name /etc/apparmor.d/disable/
sudo apparmor_parser -R /etc/apparmor.d/profile.name
More complete instructions available here:
https://help.ubuntu.com/community/AppArmor
You can also disable AppArmour, for the purposes of testing (I don't like to advise anyone to remove security features permanently), with:
sudo systemctl stop apparmor
sudo systemctl disable apparmor

PRU won't initialize for hcsr-04 ultrasonic sensor (Beaglebone black)

In order to use the hcsr-04 ultrasonic sensor using BBB's PRU, I have tried this git :
https://github.com/HudsonWerks/Range-Sensor-PRU
I get the error "the PRU failed to open", when I try to start "rangepru".
Doing some research, I feel like that is because my PRU is not initialized and that I should do : "echo BB-BONE-PRU-01 > /sys/devices/bone_capemgr.8/slots" to correct it.
But with the recent debian versions (4.x), the cape manager changed and I found the file "slots" at:
/sys/devices/platform/bone_capemgr/slots ; BUT, there is no way to open, modify it :
- using "nano" I get "slots.swp Permission denied"
- and by typing the correct echo command (modified from the one above) : I get : "write error: No such file or directory"
Best regards,
Elrise
You are probably missing a suitable device tree driver.
Try to follow the instructions on:
https://github.com/luigif/hcsr04
related to the compilation and installation of the driver.
If you have a proper development environment, executing make install should do everything for you.

Execute an application before log-in time forever in linux

I am working on a BBB device running on an Angstrom image and the display panel is a 7 inch LCD cape. I want to start an application as soon as log-in message prompts means the application should get start automatically just after the booting. To achieve this I tried
1) To put my script files in /etc/init.d and linked the script with /etc/rc5.d as S99myscript and then updated the rc.d
But it was not an successful attempt.
2) I changed the /etc/issue file a little bit and to invoke the script i appended myscript file in the last as this.
. /home/root/myscript
// tried it like this also
sh . /home/root/myscript
but this time also i couldn't get my desired result.
What's i am missing ? Or how can I get the result.
The service file
Status of service file

Problems with EXEC pplcd from PeopleSoft Application Engine

On a Unix server, I am running an application engine via the process scheduler.
In it, I am attempting to use a "zip" Unix command from within an "Exec" pplcode function.
However, I only get the error
PS_Exec(P): Error executing batch command with reason: No such file or directory (2)
I have tried it several ways. The most logical approach I thought was to change directory back to the root, then change to the specified directory so that I could easily use the zip command, such as the following...
Exec("cd / && cd /opt/psfin/pt850/dat/PSFIN1/PYMNT && zip INVREND INVREND.XML");
1643 12.20.34 0.000048 72: Exec("cd /opt/psfin/pt850/dat/PSFIN1/PYMNT");
1644 12.20.34 0.001343 PS_Exec(P): Error executing batch command with reason: No such file or directory (2)
I've even tried the following....just to see if anything works from within an Exec...
Exec("ls");
Sure enough, it gave the same error.
Now, some of you may be wondering, does the account that is associated with the process scheduler actually have authority on this particular directory path on the server ? Well, I was able to create the xml file given in the previous command with no problems.
I just cannot seem to be able to modify it with the Exec issuance of Unix commands.
I'm wondering if this is an error of rights and permissions from the unix server with regards to the operator id that the process scheduler is running from. However, given that it can create and write to a file there, I cannot understand why the Exec command would be met with any resistance....Just my gut shot in the dark...
Any help would be GREATLY appreciated!!!
Thanks,
Flynn
Not sure if you're still having an issue, but in your Exec code, adding the optional %FilePath_Absolute constant should help. When that constant is left off, PS automatically prefixes all commands with <PS_HOME>. You'll have to specify absolute paths with this flag on though. I've changed the command to something that should work.
Exec("zip /opt/psfin/pt850/dat/PSFIN1/PYMNT/INVREND /opt/psfin/pt850/dat/PSFIN1/PYMNT/INVREND.XML", %FilePath_Absolute);
The documentation at PeopleBooks is a little confusing sometimes, but it explains it fairly well in this case.
You can always store the absolute location in a variable and prefix that to your commands so you don't have to keep typing out /opt/psfin/pt850/dat/PSFIN1/PYMNT/.

Launching instruments from command line with iPhone simulator

Following this question, how do I launch instruments with iPhone simulator as a device.
I tried this:
$ instruments -t /Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w iphonesimulator5.0 MyApp.app
But I get this error:
Instruments Usage Error : Device failed to become ready for use.
-w <deviceID> is used only when you wish to specify a hardware device as the destination (the 'deviceID' here is the Identifier of the device, found in the Organizer of Xcode).
Instead of using -w, you can specify a flag during the build to force instruments to use iPhone. Details can be found here.
I was doing it as follows:
1.I created a template in which I was calling my UI Automation Main file that Triggers running all the scripts.
EX:
//Main.js file will run auto.js scripts
//auto.js is my main file in which I am running all the scripts
//Main.js file
#import "auto.js"
auto.run();
//Now open terminal and run the following command.
1. Go to the directory where you saved your template
2.Copy the location where you simulator (full path) is
Than run the command below:
instruments -t ./NameOfYourTemplate.tracetemplate /Users/swathyvalluri/Debug-iphonesimulator/MyApp.app
Note : Create a new file in the template and copy the contents into it what ever you want to put, otherwise it will look for Main.js file in your locally and will fail when running it on another server.
Please let me know if you need more help :)
Device id means here UDID of the device.
Also see the link below, it is very useful :
http://lemonjar.com/blog/?p=69

Resources