LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: 0
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..

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

Rep: Reputation: 49
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
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:
Quote:
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, 09:42 AM   #3
nuwen52
Member
 
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:
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.
 
Old 07-01-2009, 01:58 AM   #4
squall0366
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
 
  


Reply


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 02:54 AM
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 01:10 PM
Combining files into one cobra7x Linux - General 10 05-05-2005 02:39 AM
Write-combining thiagorobert Linux - Software 2 05-10-2004 04:50 PM
Combining 2 perl scripts together meluser Programming 5 03-18-2003 07:46 AM


All times are GMT -5. The time now is 06:59 AM.

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