#!/usr/bin/env bash #!/bin/bash #!/bin/sh filename='/home/supersaiyan/sample1.sh' for i in 1 2 3 4 5 do echo "String $i" x1+="String"$i done echo "#Added string is: $x1" >> $filename echo "The following string has been added to the file: $x1"
Here’s the bash script I created which runs fine when using the bash command. It doesn’t work in crontab though.
SHELL=/bin/bash PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 5 * * * * echo '#tanginamo cron tester' >> /home/supersaiyan/samplerz.sh * * * * * /bin/bash /home/supersaiyan/sample1.sh
Here’s what I put in crontab. The first line is just for testing and is working fine so I’m really lost on why the second one isn’t working.
EDIT: Tried removing the SHELL and PATH lines to no avail
The .sh file is already modified as executable
Your output should be going to a different file than your actual script file.
You need to change :
…and run the script again.
You may want to review it’s contents past line 10 or so.
Answered By – ewoj