crontab not running wget - cron

So I'm trying to run a wget command using crontab every 5 minutes. My problem that I have is it's just not running. I did crontab -l to see what was running, the command is there.
the command is: wget --output-document="/Users/proudowner/Desktop/tfgo/bp.json" http://backpack.tf/api/IGetMarketPrices/v1/?key=<key>
And the error log says: /bin/sh: wget: command not found
The command also runs fine without crontab.

In crontab -e, make this your first line:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Then wget should work without specifying the full path.
You can also just specify the full path to wget (which wget to find it):
/usr/bin/wget --output-document="/Users/proudowner/Desktop/tfgo/bp.json" http://backpack.tf/api/IGetMarketPrices/v1/?key=55085a94ba8d88d1538b4576

Related

Crontab executes shell script: Mount error(13): Permission denied

I have got a RasPi and I actually try to execute a shellscript to automount a folder at every Reboot.
Script Command is:
sudo mount -t cifs 'folderpath' 'pointtomount' -o username=xxx,password=xxx,sec=ntlm
It works perfect if I use it manually but via cronjob it responses "Mount Error(13): Permission denied" and the mount can't be executed.
Means cronjob executes the file at least.
My idea was to mount it manually and check if automount is disabled in /etc/fstab or /etc/mtab. As it's just a folder I only found it in mtab.
I can't write in it but nowhere's "noauto" in the options so probabbly everything is correct.
Not certain if it has sth. in common with crontab execute rights but ls -lha /usr/bin/crontab output is -rwxr-sr-x 1.
If anyone of you got any clues how to solve this problem, i'd appreciate help.
Thanks
EDIT1:
Okay after hours and hours it seems to be working in /home/pi/.config/lxsession/LXDE-pi/autostart.sh (type "sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart.sh"). In that file I wrote "#/home/pi/scripttoexecute.sh". In my executescript I wrote "sudo mount -t cifs 'foldertomount' 'directorypath' -o credentials=/root/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777,sec=ntlm". Obviously to use the smbcredentials file, write "sudo nano /root/.smbcredentials" and in there "username=xxx" and next line "password=xxx" and optional domain.
Thanks to all and I hope that this might save someone elses time.
Not sure if it has sth in common with apt-get upgrade and apt-get update before.
Couple things here, first off every user can have their own crontab. For example:
crontab -e # Edit crontab of current user
crontab -u root -e # Edit crontab of root user (might need sudo for this)
crontab -u www-data -e # Edit crontab of www-data user
Another thing is that if you don't use crontab -e to edit the file, and actually edit the /etc/crontab file directly (do something like vim /etc/crontab), you can actually specify the user you'd like to run the cron as:
* * * * * root mount -t cifs /path/to/folder /point/to/mount -o username=xxx,password=xxx,sec=ntlm
To run via root's crontab at reboot, type:
sudo crontab -e
And add this line:
#reboot mount -t cifs 'folderpath' 'pointtomount' -o username=xxx,password=xxx,sec=ntlm
But really, shouldn't you be adding your auto-mounts to /etc/fstab?

Installation of Cron in cygwin

When I run the following command in cygwin,
$ cygrunsrv -I cron -p C:\cygwin64\bin --args -n
I get the following error
cygrunsrv: Given path doesn't point to a valid executable
Why am I getting this error?
You only gave a folder and not a path to the executable. Besides this I wouldn't recommend to use windows paths in cygwin, this can cause errors. You should write /cygdrive/c/cygwin64/bin/something instead of C:\cygwin64\bin\something.exe
Perhaps you are looking for an
installation guide, and you would like to do something like this:
Install cron as a windows service, using cygrunsrv:
cygrunsrv -I cron -p /usr/sbin/cron -a -D
net start cron

Bash: sourcing file as user from script

I am creating a script meant to be run as superuser that reads a file and runs a number of scripts on behalf of all users. The important bit is this:
sudo -u $user -H source /home/$user/list_of_commands
However, whether I encose the command with quotesor not, this fails with:
sudo: source /home/user/list_of_commands: command not found
I have even tried with the . bash builtin:
sudo: . /home/user/list_of_commands: command not found
Of course running source outside a sudo environment works. I thought there might be a PATH problem, and I tried to bypass it by providing the full path to source. However, I cannot find the executable: which source returns which: no source in (/usr/local/sbin:usr/local/bin:usr/bin). So I'm stuck.
How do I make a script source a file as a user?
source is a builtin not a command, use it with bash -c:
sudo -u $user -H bash -c "source /home/$user/list_of_commands"

rundeck - switch to root user in job script

Logging via terminal I can switch to root user fine:
ubuntu#ip-10-0-0-70:~$ sudo -s
root#ip-10-0-0-70:~# whoami
root
So I created in rundeck a job script with this:
whoami;
echo "1st step";
sudo -s;
echo "2nd step";
And when I run this, it prints:
ubuntu
1st step
After print '1st step' it get stucked forever. Seems a problem with sudo -s command.
tried sudo -i but the same happens
tried sudo su - root but the same happens
rundeck is logging as ubuntu user, me too
any idea to switch to root in rundeck script?
This is the expected behaviour.
You are running a shell via 'sudo -s' and then not leaving/exiting it ! So it waits forever for somethig that won't come.
You can probably add 'sudo' as an Advanced option of your script (where it says "Run script with an interpreter or prefix. E.g.: sudo, time:").
But it will run your whole script as root.
If you just want a specific command to be run as root , just prefix your command with sudo as so:
sudo "enter_your_command_to_be_run_as_root_here"
Entering the command prefixed by Sudo will generate the following error on most linux distributions.
sudo: sorry, you must have a tty to run sudo
You can enable sudo without tty by running 'visudo' and commenting out the defaults line or removing 'requiretty' from the defaults line.
Details can be found here:
http://www.cyberciti.biz/faq/linux-unix-bsd-sudo-sorry-you-must-haveattytorun/

cgMiner Auto-Start on Raspbian

I am trying to make cgMiner auto-start when my Raspberry Pi (Raspbian Linux) starts.
Edited the rc.local file:
sudo nano /etc/rc.local
and added this line:
nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
and cgMiner doesn't start. If I type in terminal the exact same line with sudo in front it works perfectly.
sudo nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
What can I do?
I think it is related to the path or better the current working directory.
You are using ./cgminer and not a full path. So either use the full path or first cd to the directory containing the cgminer program.
Also have a look at the following page over at adafruit doing the exact same thing you are trying to accomplish
http://learn.adafruit.com/piminer-raspberry-pi-bitcoin-miner/configure-auto-start
Adafruit has the following code in /etc/rc.local
cd /home/pi/PiMiner
python PiMiner.py &
cd ..
nohup ./cgminer-3.1.1/cgminer --config /home/pi/cgminer.conf -S /dev/ttyUSB0 -S /dev/ttyUSB1 >/dev/null 2>&1&
The first and third line (the cd commands) ensure that the folder containing the folder containing the cgminer command is the current directory.
From the two cd commands adding the following command before the line containing the cgminer command would solve your issue
cd /home/pi
I seem to have found the solution for this problem, assuming it is the same as for bfgminer.
After spending a full day playing with init.d scripts, I found the simplest way is to make sure your cgminier.conf file has all the arguments in then add the following to the end of /etc/rc.local
cd /home/YOURNAME/bfgminer
sudo ./bfgminer
It ran without the sudo part, but didn't start up my block erupter without it.
I also managed to get it running from init.d, but had issues with it preventing system rebooting when done that way.
Hope that helps

Resources