I’m trying to schedule a python script to run via crontab and it’s not working. This is on Citrix’s XenServer platform which is Linux.
The script runs fine from the command prompt, but when I run it via cron i get an error:
File "./sshkill.py", line 3 ps -u root -f | grep "ssh grpadmin@192.168.200.20" | while read psline; do ^ SyntaxError: invalid syntax
The script is:
#!/bin/sh ps -u root -f | grep "ssh [EMAIL="grpadmin@192.168.200.20"]grpadmin@192.168.200.20[/EMAIL]" | while read psline; do pid=`echo $psline | awk '{print $2}'` ppid=`echo $psline | awk '{print $3}'` if test $ppid -eq '1' ; then kill $pid fi done
and the crontab entry I have is:
2 * * * * /usr/bin/python /usr/bin/sshkill.py > /tmp/sshkill.txt 2>&1
Any ideas?