0

My script is working manually but not working on crontab.I read all topics about this issue I tried so many things to execute via crontab but didnt work.

My script is below.

#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
nodetool status > cqlsh_control.txt
cs1=`more cqlsh_control.txt | awk '{print $1}' | sed -ne 6p | cut -d"%" -f1`
SLACK_ICON=":red_circle:"
if [ "$cs1" != "UN" ]; then

curl -S -X POST --data "payload={\"text\": \"{Cqlsh is not responsing Cassandra2}  \",\"username\":\"CQLSH\",\"icon_emoji\":\"${SLACK_ICON}\"
}" https://hooks.slack.com/services/T05xxxxW/B7xxxxxx09/QdotCzoxxxxxxxHxOsrnjS

fi
getaffe
  • 41
  • 1
  • 7
  • 1
    When you say > didnt work what specifically happened? Additionally, what does your crontab look like? – Greg Hilston Nov 22 '17 at 14:30
  • my crontab */1 * * * * /home/ec2-user/cqlsh_control.sh and also add it try different combinations crontab */1 * * * * sh /home/ec2-user/cqlsh_control.sh – getaffe Nov 22 '17 at 14:33
  • 2
    In your crontab, add this: `>/tmp/out1 2>/tmp/out2`. This way you will see the output and errors your script encountered. Also check your emails, crontab mails out the output from scripts. Another thing,`*/1` is the same as `*` since crontab does not run more often than once every minute. – Nic3500 Nov 22 '17 at 14:38
  • try this https://stackoverflow.com/a/47283287/1135424 – nbari Nov 22 '17 at 15:08
  • Possible duplicate of https://stackoverflow.com/questions/20582224/shell-script-not-running-via-crontab-but-runs-fine-manually but see also the troubleshooting instructions in the [`crontab` tag wiki](/tags/cron/info). – tripleee Nov 23 '17 at 08:38

1 Answers1

-4

Edit the crontab and put shell /bin/sh before script like below.

*/1 * * * * /bin/sh /home/ec2-user/cqlsh_control.s

Rajesh
  • 1
  • 2
  • The OP's script seems to be portable to `/bin/sh` so this is harmless in this case, but as long as the shebang says `/bin/bash` this is *exactly* the wrong advice. See also https://stackoverflow.com/questions/47438573/how-to-protect-virtual-machine-data-from-a-vds-provider – tripleee Nov 23 '17 at 06:47