user3694193
user3694193

Reputation: 7

Crontab Shell Script

Iam facing some issue with shell script which is processed through crontab. I Get email with these errors:

checkprocess.sh: line 2: 
: command not found
checkproces: line 4: syntax error near unexpected token `in
'
checkproces: line 4: `case $PROCESS_COUNT in

Here is the Shell Script Code:

#!/bin/sh

PROCESS_COUNT=$(ps -fu root | grep serv45svp | grep -v grep | wc -l)
case $PROCESS_COUNT in
0) /root/pro3/serv45svp &
;;
1) #OK, Program Running once
;;
*) #OK, program Running multiple time
;;
esac

Upvotes: 0

Views: 316

Answers (1)

Barmar
Barmar

Reputation: 782653

Your script has CRLF at the end of the lines, instead of LF. If you edit a Unix script on Windows, you have to fix it with dos2unix.

On Unix, lines end with a single LF character. On DOS/Windows, lines end with a CR character followed by a LF character.

If you copy a file from Windows to Unix in binary mode, the line endings will not be converted. Unix doesn't recognize the CR characters as being anything special, it thinks they're part of the command name or arguments. This causes errors because the commands and arguments shouldn't end with this extra character.

The dos2unix utility removes these extraneous CR characters.

Upvotes: 1

Related Questions