Touch Challenge


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Touch Challenge
# 1  
Old 08-04-2012
Touch Challenge

I've been given a directory full of subdirectories full of logfiles of the same name:

Code:
/logfiles/day1/file1/blockednodes.csv
day1-14
file1-48

The above is the actual directory structure for 14 days worth of a logfile that is generated every 30 minutes. It's been done this way to preserve the identicle file name "blockednodes.csv"

I've been tasked with using touch to update each of the 48 files, for each of the 14 days, with the date and time from 0000 on 25/07/2012 onwards.

I have managed the following line so far, but can't seem to get figure out how to include the time?


Code:
for i in {1..14}; do for j in {1..48}; do echo $(date +%Y%m%d --date="2012-07-24 + $i days") Day$i/File$j/BlockedNodes.csv; done; done

Output:
Code:
20120725 Day1/File1/BlockedNodes.csv
20120725 Day1/File2/BlockedNodes.csv
20120725 Day1/File3/BlockedNodes.csv
20120726 Day2/File1/BlockedNodes.csv
20120726 Day2/File2/BlockedNodes.csv
20120726 Day2/File3/BlockedNodes.csv

Can anyone suggest a way of adding the hour and minute in here?

Any help is appreciated.

Thanks and regards
Cludgie

Last edited by Scott; 08-05-2012 at 06:32 PM.. Reason: Code tags
# 2  
Old 08-04-2012
From man touch:

Code:
       -t STAMP
              use [[CC]YY]MMDDhhmm[.ss] instead of current time

# 3  
Old 08-04-2012
Thanks for the suggestion Corona688. Can you suggest how I automate this for 1500+ files in multiple directories of their own, as above?

Thanks
Cludgie
# 4  
Old 08-04-2012
math?

Code:
 for j in {1..48}; do ((h=(j-1)/2,m=(j-1)%2*30)); date +%Y%m%d%H%M -d "2012-07-24 + $i day $h:$m"; done

or maybe not subtract 1 from j, since file1 would be from 0000-0030, it'd want time 0030. the last file would be 2359 ... ?

Last edited by neutronscott; 08-04-2012 at 10:18 PM.. Reason: put it in the date call.
# 5  
Old 08-05-2012
Is the find command of any use?

Code:
   cd /<your subdir>
   find . -depth -type f

This find command will just list the files. From here you can -exec your touch command.

Code:
   find . -depth -type f -exec touch <do whatever> {} \;

or maybe use xargs if the number of files is really high.

The -exec can be calling a script or it can do the touch command directly.

Last edited by Scott; 08-05-2012 at 06:32 PM.. Reason: Code tags
# 6  
Old 08-05-2012
Thanks for the replies. I should probably mention, that I'm completely new to this.

neutronscott:

I've tried to add your suggestion to mine, but can't seem to get it to work. It seems to spew the contents of the logfiles to the screen...

Code:
$ for i in {1..14}; do for j in {1..48}; do touch -d "((h=(j-1)/2,m=(j-1)%2*30))"; date +%Y%m%d%H%M -d "2012-07-24 + $i day $h:$m"; Day$i/File$j/BlockedNotdes.csv; done; done

raggmopp:

Does find, find files in any particular order? As the files are all of the same name, would I be able to guarantee that the correct files would be found and updated in the correct order?


Thanks and regards
Cludgie

Last edited by Scott; 08-05-2012 at 06:33 PM.. Reason: Code tags
# 7  
Old 08-05-2012
Quote:
Originally Posted by Cludgie
Thanks for the suggestion Corona688. Can you suggest how I automate this for 1500+ files in multiple directories of their own, as above?
I've given you all the pieces. Have you tried anything with them?

You need a [[CC]YY]MMDDhhmm[.ss] date. How do you make a [[CC]YY]MMDDhhmm[.ss] date?

man date would be a good start. What do those % things you're putting into date mean?

Code:
...
       %d     day of month (e.g., 01)
       %H     hour (00..23)
       %m     month (01..12)
       %M     minute (00..59)
       %S     second (00..60)
       %Y     year
...

So you can make a date of the form required by giving it the right format string.

So that'd be touch -t $(date -d "2012-07-24 + $i day" "+%Y%m%d%H%M%S") filename
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Anyone like a challenge?

I have searched through google, and this forum to try and find the answer, but alas, nothing quite hits the whole answer. I am trying to read the last line (or lines) of some log files. I do this often. The files are named sequentially, using the date as part of the file name, and appending... (18 Replies)
Discussion started by: BatterBits
18 Replies

2. Shell Programming and Scripting

PS1 challenge

Ok then i Have a challenge for you : Give me PS1 so that it always display the least 2 levels of directory (except if i am above of course) I want it this way : so if i go to / /home/ /home/user /home/user/whatever /home/user/whatever1/whatever2 my PS1 should respectively... (12 Replies)
Discussion started by: ctsgnb
12 Replies

3. UNIX for Dummies Questions & Answers

Touch all files and subdirectories (recursive touch)

I have a folder with many subdirectories and i need to set the modified date to today for everything in it. Please help, thanks! I tried something i found online, find . -print0 | xargs -r0 touch but I got the error: xargs: illegal option -- r (5 Replies)
Discussion started by: glev2005
5 Replies

4. Shell Programming and Scripting

Need complex script, anyone up for a challenge?

Default shell is /usr/bin/zsh Script will be running #!/bin/bash Need to pull information from database while using other scripts already made (not by me). Ok, so i need a script pulling certain information about a customer's router interfaces. I am using a ROUTER-DNS-NAME as variable $1 I... (3 Replies)
Discussion started by: ///NNM
3 Replies

5. Shell Programming and Scripting

regex challenge

Here's a regex substitution operation that has stumped me with sed: How do you convert lines like this: first.key ?{x.y.z} second.key ?{xa.ys.zz.s} third.key ?{xa.k} to: first.key ?{x_y_z} second.key ?{xa_ys_zz_s} third.key ?{xa_k} So i'm basically converting all the... (11 Replies)
Discussion started by: neked
11 Replies

6. Shell Programming and Scripting

sed xml challenge

I have a web xml file that looks like this: <allinfo> <info> <a>Name1<\a> <b>address1<\b> <c>phone1<c> <\info> <info> <a>Name2<\a> <b>address2<\b> <c>phone2<c> <\info> <\allinfo> I want to use sed to... (2 Replies)
Discussion started by: katrvu
2 Replies

7. Shell Programming and Scripting

sed replacement, challenge one!!!!

Hi all, Thanks in advanced. This question really bothered me much. What i want is to replace any times of repeated 'TB' to 'T', below is example. It can be fullfil by AWK and perl, but my desire is using SED to realize it. So here means we treat TB as a whole part, which means 's/TB*/T/'... (4 Replies)
Discussion started by: summer_cherry
4 Replies

8. Shell Programming and Scripting

AWK Challenge

I have the following text Microsoft iSCSI Initiator version 2.0 Build 3497 Targets List: iqn.2001-05.com.equallogic:0-8a0906-daef43402-138000002a4477ba-grsrv12-extra iqn.2001-05.com.equallogic:0-8a0906-986f43402-520000002b447951-exchange ... (9 Replies)
Discussion started by: netmedic
9 Replies

9. Shell Programming and Scripting

camma challenge (in ksh)

Hi Gurus, I am a starter in ksh scripting I have a requirment where i need to ucertain that each line contain only 5 occurances of "," (comma) in a CSV file ; I don't want to use perl,is it possible in ksh;; Kindly help I am going to read CSV file and ; redirect all those lines which are... (3 Replies)
Discussion started by: Amresh Dubey
3 Replies

10. UNIX for Advanced & Expert Users

safeword challenge

Hi, there are some servers here at work which issue a Safeword challenge after I login. Can anyone tell me exactly how the challenge/response system works? In particular, how are the valid keys decided? (2 Replies)
Discussion started by: blowtorch
2 Replies
Login or Register to Ask a Question

Featured Tech Videos