[Solved] How to tar data along with current system date and time.?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] How to tar data along with current system date and time.?
# 1  
Old 01-31-2013
[Solved] How to tar data along with current system date and time.?

Hi all,

Following is my small script:-
Code:
#!/bin/ksh
for i in `cat /users/jack/mainfile-dr.txt`
do
sudo cp -r $i /users/jack/DR01/.
done
cd /users/jack/DR01/
sudo tar cvf system1-DR.tar *
scp system1-DR.tar backupserver:/DRFiles/system1
sudo rm -rf  system1-DR.tar

In this script I copy some imp files to one local folder then tar it and send it via scp to backupserver .

my question is how tar these content along with the current time and date of system when it gets compressed(tared).

something like
Code:
system1-DR.11Jan2013-08:12:31.tar

Could you please guide me on this.
I am getting interest in scripting now, I am beginner, I need your advice.

Thanks in advance,
Manali
# 2  
Old 01-31-2013
That is Dangerous Backticks

Use a while loop instead to read the file, here is the modified code to create tar file with time-stamp:
Code:
#!/bin/ksh
while read i
do
        sudo cp -r "$i" /users/jack/DR01/.
done < /users/jack/mainfile-dr.txt

cd /users/jack/DR01/
TS=$( date +"%d%b%Y-%H:%M:%S" )
sudo tar cvf system1-DR.${TS}.tar *
scp system1-DR.${TS}.tar backupserver:/DRFiles/system1
sudo rm -rf system1-DR.${TS}.tar

This User Gave Thanks to Yoda For This Post:
# 3  
Old 01-31-2013
Thanks bipinajith for reply...

So you mean to say below script will also work ? with two addtional line above, I hope it will


Code:
#!/bin/ksh

cd /users/jack/DR01/
sudo cp /etc/default/passwd /users/jack/passwd-default

while read i
do
        sudo cp -r "$i" /users/jack/DR01/.
done < /users/jack/mainfile-dr.txt

cd /users/jack/DR01/
TS=$( date +"%d%b%Y-%H:%M:%S" )
sudo tar cvf system1-DR.${TS}.tar *
scp system1-DR.${TS}.tar backupserver:/DRFiles/system1
sudo rm -rf system1-DR.${TS}.tar

Why you say "That is Dangerous Backticks", can you explain in single line, I saw that link but no idea..

Thanks again,

I will check your date code in my script now.
# 4  
Old 01-31-2013
There is a kernel limitation ARG_MAX. If the data fetched inside the back-ticks is not within this limit, your script will fail.

So it is always a good programming practice to avoid using such construct.
This User Gave Thanks to Yoda For This Post:
# 5  
Old 01-31-2013
Hey bipinath,
Thanks for reply but
I get error. which doing scp
Code:
ssh: system1-DR.31Jan2013-21: node name or service name not known

Please advise.
Thanks,

---------- Post updated at 02:07 AM ---------- Previous update was at 02:07 AM ----------

however the tar file got removed by the script.

---------- Post updated at 02:09 AM ---------- Previous update was at 02:07 AM ----------

else I can write it down
Code:
scp *.tar backupserver:/DRFiles/system1

---------- Post updated at 02:09 AM ---------- Previous update was at 02:09 AM ----------

tar file showing Date but not Time
# 6  
Old 01-31-2013
The colon : in the time-stamp is causing issue. Create time-stamp without colon :
Code:
TS=$( date +"%d%b%Y-%H-%M-%S" )

This User Gave Thanks to Yoda For This Post:
# 7  
Old 01-31-2013
wait I need to ask something more

---------- Post updated at 02:22 AM ---------- Previous update was at 02:17 AM ----------

wow sir it worked!
but one question
system1-DR.31Jan2013-21-49-05.tar is the file created
and time on local system is:
Code:
Thursday, January 31, 2013  9:49:29 PM CET

and on target system is
Code:
Thu Jan 31 23:27:42 CET 2013

---------- Post updated at 02:22 AM ---------- Previous update was at 02:22 AM ----------

so what is the time tar file captured ???

---------- Post updated at 02:24 AM ---------- Previous update was at 02:22 AM ----------

I guess it is amsterdam local time..?
is it?

---------- Post updated at 02:25 AM ---------- Previous update was at 02:24 AM ----------

You gave me great things to learn, thanks for till now whatever You have taught me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to substract date with current date and time

I have below file which contain the date in column 3,4,5 12345 open 10/10/13 10:08 PM 3 application is in java 67899 open 12/10/13 2:31 AM 2 apps can be reach 23456 open 11/9/13 2:31 AM 4 java is OK 65432 open 12/10/13 10:07 PM 9 we are... (1 Reply)
Discussion started by: vijay_rajni
1 Replies

2. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

3. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

4. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

5. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

6. UNIX for Dummies Questions & Answers

Comparing Output Date to Current System Date

Hi Guys, Anyone who knows how to compare the current date with the a file containing a date, say for example I have a file that looks like this: Command was launched from partition 0. ------------------------------------------------ Executing command in server server6 Fri Dec 16... (7 Replies)
Discussion started by: rymnd_12345
7 Replies

7. UNIX for Dummies Questions & Answers

Delete a row from a file if one column containing a date is greater than the current system date

Hello gurus, I am hoping someone can help me with the required code/script to make this work. I have the following file with records starting at line 4: NETW~US60~000000000013220694~002~~IT~USD~2.24~20110201~99991231~01~01~20101104~... (4 Replies)
Discussion started by: chumsky
4 Replies

8. Shell Programming and Scripting

how to get what date was 28 days ago of the current system date IN UNIX

Hi, Anybody knows how to get what date was 28 days ago of the current system date through UNIX script. Ex : - If today is 28th Mar 2010 then I have to delete the files which arrived on 1st Mar 2010, (15 Replies)
Discussion started by: kandi.reddy
15 Replies

9. UNIX for Dummies Questions & Answers

get current system date

How do I create a shell script that would get the current system date in format of yyyymmdd and use that result to concatenate it to a filename that it would look like this: sample20051024.dat example -------- current system date: 24-Oct-2005 filename: sample.dat when the shell script... (5 Replies)
Discussion started by: wtolentino
5 Replies

10. Shell Programming and Scripting

Get date and time for past 1 hour from current date

Hi, I need to get the date and time for past 1 hour from the current date. Anyone know how to do so? Thanks (5 Replies)
Discussion started by: spch2o
5 Replies
Login or Register to Ask a Question