0

I have the below script to automatize with cron, but when i run it "./" its work, but on cron dosen't work.

I tried many things, like a change the sh to bash for cron. Variables on my script, etc...

#!/bin/bash

DATE=$(/bin/date +%d-%m-%Y-%H-%M-%S)

USERFW="xxxx"

IPSERVER=$(ip route get 1.2.3.4 | awk '{print $7}')


for SW in `more fw.txt `
do
/usr/bin/sshpass -p "Hs@Pr&v3nT!" /usr/bin/ssh -tt -o StrictHostKeyChecking=no $USERFW@$SW <<EOF
execute backup config tftp SW-$DATE $IPSERVER
exit
exit
EOF
done

I need this code working on crontab... does anyone help me?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • You probably also need to use an absolute path for fw.txt, and the way you're reading its contents is not good (see [BashFAQ #1](http://mywiki.wooledge.org/BashFAQ/001) and [this question](https://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash)). And I'd recommend using lower- or mixed-case variable names for your own things, to avoid accidentally reusing one of the all-caps names with a special meaning. – Gordon Davisson Sep 12 '19 at 23:47
  • owwwww... its working now... thank you so much.... – Germano Sep 13 '19 at 00:26

0 Answers0