help....generate command script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting help....generate command script
# 1  
Old 02-19-2009
help....generate command script

Please help.....

if i have a file list below :

1233743158.log
1233743410.log
1233744186.log
1233744462.log

"1233743158" is a unix time format

it's require to a script "convertime.sh" to convert unix time format to readable time format like 20090204183010 -- YYYYMMDDHHMMSS

script for convert from unix time sentence
# ./convertime.sh -d 1233743410 +%Y%m%d%H%M%S
20090204183010


i want to write a scrpit (inside use the script "convertime.sh") to generate the command like below:

cp 1233743158.log 20090204182558.log
cp 1233743410.log 20090204183010.log
cp 1233744186.log 20090204184306.log
cp 1233744462.log 20090204184742.log

Last edited by bleach8578; 02-19-2009 at 09:12 AM..
# 2  
Old 02-19-2009
MySQL

Hi,

Sorry Not sure what you are trying to say...

if you want to change file name with respective timestamp then..

we can use below command inside script.....

cp 1233743158.log `date +%Y%m%d%H%M%S`.log

what else you want to do here..

Thanks
Sha
# 3  
Old 02-19-2009
Code:
while read name
do  
   echo cp "$name" "$(date -d "${name%.*}" "+%Y%m%d%H%M%S").log"
done < file.list


Last edited by danmero; 02-19-2009 at 09:25 AM..
# 4  
Old 02-19-2009
Quote:
Originally Posted by Shahul
Hi,

Sorry Not sure what you are trying to say...

if you want to change file name with respective timestamp then..

we can use below command inside script.....

cp 1233743158.log `date +%Y%m%d%H%M%S`.log

what else you want to do here..

Thanks
Sha
if using your command only can copy the file to current time not file's real time


1233743158.log is a file name

"1233743158" is a unix time format

it's require to a script "convertime.sh" to convert unix time format to real time format like 20090204183010 -- YYYYMMDDHHMMSS

if run the script convertime.sh like below

# ./convertime.sh -d 1233743158 +%Y%m%d%H%M%S
result printout

20090204182558 <--readable time for the file 1233743158
# 5  
Old 02-19-2009
Quote:
Originally Posted by danmero
Code:
while read name
do  
   echo cp "$name" "$(date -d "${name%.*}" "+%Y%m%d%H%M%S").log"
done < file.list

file.list's content is below ??

1233743158.log
1233743410.log
1233744186.log
1233744462.log

how to apply this with convertime.sh ??
# 6  
Old 02-19-2009
MySQL

if you have *.log files in specific location:
then try the below one..


n=1
for f in `ls *.log`
do
cp $f `date +%Y%m%d%H%M%S`_$n.log
n=$(( n + 1 ))
done

Thanks
Sha
# 7  
Old 02-19-2009
Quote:
Originally Posted by bleach8578
how to apply this with convertime.sh ??
You don't need the convertime.sh Smilie this basic script will do what you want.
Code:
#!/bin/sh
while read name
do
   echo cp "$name" `date -d "${name%.*}" "+%Y%m%d%H%M%S"`.log
done < file.list

Replace the file.list by your file name, check the output and when you are satisfied remove the echo.

and please read some "Scripting for beginners"
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How do I generate a script with an inverse action?

I have an interactive script which sorts and processes a variety of filetypes from an unsorted folder into newly created directories. The script works great, But I was wondering how I could generate a script with an inverse action so that I could unwind / undo the executed script and its sorting... (3 Replies)
Discussion started by: Braveheart
3 Replies

2. Shell Programming and Scripting

Generate documentation for a shell script

Hi, I've written a shell script with proper intentation and commenting structure. However, I would like to generate documentation for the shell which I have written. Is there any tool as such to generate it like we have javagen/docgen ? Please help. Thanks, Arjun (0 Replies)
Discussion started by: arjun_arippa
0 Replies

3. UNIX for Dummies Questions & Answers

Need script to generate file.

Hi I have a file "test" with data as below 1,APRIL,NEW,"New market,delhi,pune,India",RECENT, 254664 2,MARCH,OLD,"New Area,Mumbai,UP,India",CURRENT, 152483 So I want a script which provides output as below 1,APRIL,RECENT,254664 2,MARCH,CURRENT,152483 I am aware we can use awk/sed... (9 Replies)
Discussion started by: sv0081493
9 Replies

4. Shell Programming and Scripting

generate a script that will do the following

I need to write a shell script that will do all this: Go to server directory, for example (/xyz/outbound) In the outbound folder, get the list of the (old) directories created or modified at least two days before the date when script is run. The list will have the names of directories, some... (2 Replies)
Discussion started by: chako_3
2 Replies

5. Shell Programming and Scripting

Script to generate passwd comb.

Hi I created a gnupg password which I later forgot clumsy enough (after a holiday). I can always create a new one but unfortunately I have some files on the computer that I encrypted with it and would like to access it. I remember parts of the password and was wondering what's the the best way to... (0 Replies)
Discussion started by: zaonline
0 Replies

6. Shell Programming and Scripting

How to generate cntl+c interrupt through script?

Hi all, can anyone tell me how to generate control+c interrupt through shell script. (2 Replies)
Discussion started by: rohitmahambre
2 Replies

7. Shell Programming and Scripting

Generate command with awk

Hello, I have the line underneath generated by lssyscfg command: """51/client/1/pcyaz0hjfv00-vio1/651/c050760107fd0466,c050760107fd0467/1"",""52/client/2/pcyaz0hjfv01-vio2/652/c050760107fd0468,c050760107fd0469/1"",""31/client/1/pcyaz0hjfv00-vio1/375/c050760107fd046a,c050760107fd046b/1"""... (1 Reply)
Discussion started by: khalidou13
1 Replies

8. Shell Programming and Scripting

Script to generate a list of number

How can I generate a list of numbers and place all of these numbers in a line-by-line into a file. I am new to scripting actually. 0501000000 to 0509999999 i.e. 0501000000 0501000001 ...... 0509999999 set 02 0551000000 to 0559999999 i.e. 0551000000 0551000001 ...... 0559999999 ... (3 Replies)
Discussion started by: noo
3 Replies

9. Shell Programming and Scripting

how to generate html file using script?

Hi Friends I have an requirement that i need to generate html file using script. and the script output shold keep adding to that html file like tablewise. can anyone please help me out in this. thanks Krish. (2 Replies)
Discussion started by: kittusri9
2 Replies
Login or Register to Ask a Question