I made a shell script to connect using ssh with password to another linux server, get the details of a specific file and save it in a log file in the origin server. Manually works without problem but with the /etc/crontab doesnt update the file. (I think it may be the connection because if I try to write a test text in the file it works fine).
I tried with tee -a command and the >> command to update the file and both fails.
This is my code
#! /bin/bash
sshpass -p "password" ssh "username"@"ipserver" ls -l /filepath/file.txt | tee /home/user/test/details.log
I omitted the password, username and ip for discretion.
This is the /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
* * * * * user-name command to be executed
*/1 * * * * root /home/test/script.sh
Hope you can help me.
Thanks