I have a bash script that I'm trying to run remotely from another system. It is to add a cronjob to a user on the remote system.
I run this from the local system.
ssh root@remote_system 'bash -s < /home/user_name/test2.sh'
this is the script on the remote system that gets run.
#!/bin/bash set -x #valhost=$(hostname) if [ -d /home/user/junk ] then touch /var/spool/cron/user_name crontab -l -u user_name > /home/user_name/mycron chmod +x /home/user_name/mycron echo "0 0 * * * /bin/find /home/user_name \( -name '*' \) -mtime +45 -delete" >> /home/user_name/mycron crontab -u user_name /home/user_name/mycron elif [ -d /home/user_name/tmp ] then touch /var/spool/cron/user_name crontab -l -u user_name > /home/user_name/mycron chmod +x /home/user_name/mycron echo "0 0 * * * /bin/find /home/user_name \( -name '*' \) -mtime +60 -delete" >> mycron crontab -u user_name /home/user_name/mycron else echo "directory does not exist on" $HOSTNAME > /home/user_name/jbossjunk fi
It checks to see if a directory is there and then puts a specific entry in the crontab. The script works fine when I run it on the actual remote system. But when I run it on the local the echo doesn't output to the "mycron" file. I've searched a lot of places and found nothing on the syntax I could use. I've tried numerous variations of syntax on the line and come up with bad results. Can someone give me the syntax that would work for this "echo" line running the script remotely