0

I was trying to schedule this script onto the crontab but the script is not running as expected. I can execute the script manually and it runs as expected generating the list using the command list-users and emails the list but it does not execute when scheduled in the crontab. I have tried to run this script as a .sh file and a .bash file. This is Script.sh that I am trying to run:

echo "Starting script"
list-users primary_number organization.eq.1002 > /var/tmp/ListUserOutput.txt
mail -s 'List Users Org 1002' example@gmail.com < /var/tmp/ListUserOutput.txt
echo "Ending script"

This is how it is scheduled in the crontab:

0 9 * * * /var/tmp/Script.sh > /var/tmp/Script.log 2>&1

And this is the output of the Script.log

/bin/sh: /var/tmp/Script.sh: /bin/bash^M: bad interpreter: No such file or directory
Cyrus
  • 84,225
  • 14
  • 89
  • 153
Riley Spotton
  • 231
  • 1
  • 2
  • 8
  • 1
    You probably have a carriage return character at the ends of your lines, e.g. if the file was created with a Windows editor. This is harmless if the script is being executed directly by the shell, but not if you try to run it as a standalone command. Try filtering the script through `fromdos` or a similar tool. – Nate Eldredge Feb 24 '21 at 19:32
  • I suggest: `dos2unix /var/tmp/Script.sh` – Cyrus Feb 24 '21 at 19:49
  • As an aside, the temporary file can easily be avoided; use a pipe. – tripleee Feb 24 '21 at 19:54
  • The name of the file doesn't matter, though using `.sh` on files which are not `sh` scripts is confusing to human readers. A general convention is for scripts to not have an extension at all. – tripleee Feb 24 '21 at 19:56

0 Answers0