We help IT Professionals succeed at work.

script Expect (SCP and tar)

amadojimenzp
amadojimenzp asked
on
Good morning,

I have a solaris system with expect installed, I don't know how to achieve a script to make this: a script that can access a directory called /Backup/Online and compile everything inside with a name and a date of the previous day, after it finishes the compiling, that it send me to a remote server by scp.

I'll aprecciate your help.
Comment
Watch Question

compile?  Which compiler or just make a list of files?

Author

Commented:
A script that can access a directory called /Backup/Online and package ( command tar ) everything inside with a name and a date of the previous day, after it finishes the compiling, that it send me to a remote server by scp.

Author

Commented:
Especifically a script which can access to a directory called /Backup/Online (CD command) and that everything that is inside that directory, is converted in and archive .tar (tar -cvf command) with the name and date of the previous day.

Author

Commented:
after it is converted in a archive .tar, that it send me to a remote server by scp.
Ok.  Here it goes.  This script should be good for both bash and ksh.

#Backup directory
backupDir="/Backup/Online"

#Get yesterday' date
yesterday=$(date +%Y-%m-%d -d "1 day ago")

#Adjust this path and the name
backupName=/tmp/$backup_$yesterday.tgz

#create a backup
#excludes are sample for you.  Adjust accordingly
#these exceptions will not be backed up
#Option --one-file-system keeps the backup source limited to one
#file system.  This is useful when your backup directory has mounted
#file systems in it
#If you don't want compress it, remove z in the options are change file extension to tar
#Option p preserves permissions, but doesn't preserve ACLs, you have to use
#separate option for that

tar pcvfz --one-file-system $backupName  \
--exclude=/proc --exclude=*lost+found* --exclude=/sys \
--exclude=/boot --exclude=/media --exclude=mnt \
--exclude=/home --exclude=/etc/fstab \
--exclude=*tgz --exclude=*tmp* \
$backupDir
Sending as ssh using script is a whole new topic. You should enable public private keys for that purpose between the servers.  Once you are able to do successfully, all you need is one simple last command, in the above script

#You need IP or FQDN AND target directory AND userID on that machine
ip=192.168.0.254
dir=/path/backup
tuser=auser
scp $backupName $tuser@$ip:$dir

Author

Commented:
thank you very much farzanj.
You are welcome