Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-30-2009, 05:42 AM   #1
LQ Newbie
Registered: Jun 2009
Location: India
Distribution: RHEL 5.1
Posts: 9

Rep: Reputation: 0
combining scripts

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



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
ftp -nv < ftp_file
can any one please suggest me a way to combine the two scripts...
any suggestions will be most welcome..

Last edited by squall0366; 06-30-2009 at 06:08 AM.
Old 06-30-2009, 06:28 AM   #2
Registered: Jul 2007
Location: Belgium
Distribution: slackware64 14.2, slackware 13.1
Posts: 371

Rep: Reputation: 54
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:
cat "for ftp transfer" >> cpy_test
Adapt the script so that the names and directories match.
Add the "ftp -nv..." line to the script.

Also, there are a few odd things about your script:
tar cfz "$YESTERDAY".gz "$YESTERDAY"
You name the archive with a .gz extension, not a tar.gz extension. The guy who comes after you may think it's just a gzipped text file if you just call it $YESTERDAY.gz, but if you call it $YESTERDAY.tar.gz, he will know it's a tar archive.
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/
Old 06-30-2009, 08:42 AM   #3
Registered: Feb 2009
Distribution: Debian, CentOS 5, Gentoo, FreeBSD, Fedora, Mint, Slackware64
Posts: 208

Rep: Reputation: 46
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:
paste script

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.
Old 07-01-2009, 12:58 AM   #4
LQ Newbie
Registered: Jun 2009
Location: India
Distribution: RHEL 5.1
Posts: 9

Original Poster
Rep: Reputation: 0
kk tnks completed the script ..
used three functions ...
tnks for the advice


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining Shares DriverJC Linux - Networking 1 02-11-2007 01:54 AM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 12:10 PM
Combining files into one cobra7x Linux - General 10 05-05-2005 01:39 AM
Write-combining thiagorobert Linux - Software 2 05-10-2004 03:50 PM
Combining 2 perl scripts together meluser Programming 5 03-18-2003 06:46 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration