Showing posts with label variables. Show all posts
Showing posts with label variables. Show all posts

4/01/2020

How to pass value of a variable in ssh command

How make a script using a local or remote variable in other script


 Sample SCRIPT


 #!/bin/bash
## find the last or new backup file in the folder and create a variable name
DBFILE DBFILE=`ssh -t serverB@192.0.0.1 "sudo find /temp/backup.sql -type f -mtime -1 -name "*.sql""`

 ###( just show the name file)
echo $DBFILE  
###  send the variable local to remote server
echo here is DBFILE $DBFILE
#ssh -t serverB@192.0.0.1 "sudo cp $DBFILE /home/user/"
## Script execute remote with the variable 
#/usr/bin/scp serverB@192.0.0.1:/home/user/$DBFILE  /opt/temp