combining scripts
Hi
I need to write a script to copy a log directory generated yesterday in the format: "YYYY-mm-dd" from a fixed location to the root, tar it and then transfer to a remote server via ftp. This script is to be automated through cron for daily backup. I wrote two scripts for the same 1.) For copying file name:cpy_test YESTERDAY=`date -d "yesterday" +'%Y-%m-%d'` cp -rf /root/Desktop/testA/myfiletest/"$YESTERDAY" / tar cfz "$YESTERDAY".gz "$YESTERDAY" rm -rf "$YESTERDAY" 2.) for ftp transfer FTP_HOST="host_ip" FTP_USER="user_name" FTP_PASS="user_pass" LOC_DIR="/root" REMOTE_DIR="/var/usr_nm/log/archive" FILENAME="log*.gz" echo "open $FTP_HOST" > ftp_file echo "user $FTP_USER $FTP_PASS" >> ftp_file echo "binary" >> ftp_file echo "cd $REMOTE_DIR" >> ftp_file echo "lcd $LOC_DIR" >> ftp_file echo "mput $FILENAME" >> ftp_file echo "bye" >> ftp_file then use the following field in cron ./cpy_test ftp -nv < ftp_file can any one please suggest me a way to combine the two scripts... .. any suggestions will be most welcome.. |
Just append the second file to the first.
If you don't have a fancy copy-and-paste mechanism that you can use, just do this: Code:
cat "for ftp transfer" >> cpy_test Add the "ftp -nv..." line to the script. Also, there are a few odd things about your script: Quote:
Also, you give $YESTERDAY as the directory tar has to archive. This only works if the working directory is either / or /root/Desktop/testA/myfiletest/ . Using an extra line with "cd / " in it never hurts, and it will make your script a bit more portable. I have a hard time imagining that the scripts you posted can work together now. Please follow my advice about editing the file names and directory names. Remember, your archive is called $YESTERDAY.gz (if you use the script as you posted it) and it is located in /, not /root/ |
Another way is to create a wrapper script which calls them in order. That way, if you need to change one, you don't have to worry about modifying a combined script.
Or, build them as functions: script1() { paste script } script2() { paste script } #Main script area script1 <args> script2 <args> These are maybe more complex than needed, but it keeps the parts separate if you need to modify one part without changing the other. |
kk tnks completed the script ..
used three functions ... tnks for the advice |
All times are GMT -5. The time now is 08:36 AM. |