Reputation: 811
So I am executing this code on the local host which is accessing a remote host and executing another script:
count=$(ssh -i /home/ubuntu/***** "sh /home/ubuntu/michael/LogScript/backUpLog.sh "$1" "$2" "$3"")
echo "$count"
exit "$count"
And this is the code it is remotely connecting to and running:
count=$(grep "^$(date -d -"$1"minute +'%Y-%m-%d %H')" /var/log/*****/*****.log | wc -l)
if [ "$count" -ge "$2" -a "$count" -lt "$3" ]
then
exit 1
fi
if [ "$count" -ge "$3" ]
then
exit 2
fi
exit 0
The ssh is working correctly as I have testing with very simple scripts, but when I run the above I get exit: 3: Illegal number:
It doesn't say anything more than this. Is it because of the way I am calling count in the local script?
Upvotes: 0
Views: 311
Reputation: 123600
Your remote script returns an exit code but no output. Your local script ignores the exit code and tries to capture output.
You can change your local script to use the exit code instead:
ssh -i /home/ubuntu/***** "sh /home/ubuntu/michael/LogScript/backUpLog.sh $1 $2 $3"
exitCode=$?
echo "Command exited with $exitCode"
exit "$exitCode"
Upvotes: 1