Sorry if it's too much simple question. But I am Java developer, no idea of shell scripting. I googled, but couldn't find exactly what I am looking for.
My requirement
Can any one give me shell script for this?
This is so far I framed from suggestions. Still some questions left on my side ;)
export PRIVKEY=${private_key_path}
export RMTHOST=user@remotehost
export RMTDIR=/logs/*.log
export LOCDIR=/downloaded/logs/
export LOG=sucess.txt
scp -i $PRIVKEY $RMTHOST:$RMTDIR $LOCDIR
for i in 'ls -1 $LOCDIR/*.log'
do
echo $i >> $LOG
done
ssh $RMTHOST -c "for i in `ls -1 $RMTDIR; do mv /logs/$i /logs/$i.transferred; done"
What about this approach?
- Connect to remote server using Sftp [authentication based on pub/pri keys]. A variable to point to private key file
- Transfer files with specific extension [.log] to local server folder. Variable to set remote server path and local folder
scp your_user@server:/dir/of/file/*.log /your/local/dir
- Log all the transferred files in a .txt file
for file in /your/local/dir/*.log
do
echo "$file" >> $your_txt
done
- Rename the transferred file in remote server
ssh your_user@server -c "for file in /dir/of/file/*.log; do mv /dir/of/file/"$file" /dir/of/file/new_name_based_on"$file"; done"