How to touch a file 30min ago


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to touch a file 30min ago
# 1  
Old 06-26-2008
How to touch a file 30min ago

I know how to touch like this
Code:
touch -t 199908031046 /tmp/file1

But I want to create a cron job for touch a file which 30 min ago in Solaris which haven't -mmin

Can I use like this ? touch -t `date +%s` - 30 /tmp/file1

Because I want to file the file which older than 30min.

Thanks,

Last edited by Yogesh Sawant; 06-27-2008 at 01:26 AM.. Reason: added code tags
# 2  
Old 06-26-2008
Got perl?
Code:
#!/usr/bin/ksh
#----subtract 30 minutes (1800 seconds) from time
STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 1800);
printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')

#----create an empty file with a timestamp of 30 minutes ago
touch -t $STAMP /tmp/flagfile

#----find older files
find /start/dir -type f ! -newer /tmp/flagfile -print |\
while read FILE
do
  : something with $FILE
done

# 3  
Old 06-26-2008
You can use Tcl to achieve that

Code:
touch -t `echo 'puts [clock format [expr [clock seconds]-30*60] -format "%Y%m%d%H%M.%S"]' | tclsh` file.30min.old

tclsh is normally available in Linux
In Solaris 9 or 10, it is likely found in
/usr/sfw/bin/tclsh8.3 or
/opt/sfw/bin/tclsh8.3

Last edited by Yogesh Sawant; 06-27-2008 at 01:27 AM.. Reason: added code tags
# 4  
Old 06-26-2008
I try this script but still doesn't work

#!/usr/bin/ksh

the_hour=`date +"%H"`
the_min=`date +"%M"`
# calc_time=`expr $the_hour - 3`
calc_time=`expr $the_min - 30`
echo "The current time is $the_hour:$the_min"
# echo "This is the calculated time $calc_time:$the_min"
echo "This is the calculated time $the_hour:$calc_time"

sh -x test.sh
+ date +%H
the_hour=15
+ date +%M
the_min=43
+ expr 43 - 30
calc_time=13
+ echo The current time is 15:43
The current time is 15:43
+ echo This is the calculated time 15:13
This is the calculated time 15:13

but looks this script cannot run before every 29min or lower.
# 5  
Old 06-26-2008
ksh: tclsh: not found

> cd /usr/sfw
ksh: /usr/sfw: not found
> cd /opt/sfw
ksh: /opt/sfw: not found
# 6  
Old 06-26-2008
> sh -x test5.sh
test5.sh: syntax error at line 3: `STAMP=$' unexpected

I think I got the perl but dont know whats happen.



Quote:
Originally Posted by Ygor
Got perl?
Code:
#!/usr/bin/ksh
#----subtract 30 minutes (1800 seconds) from time
STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 1800);
printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm')

#----create an empty file with a timestamp of 30 minutes ago
touch -t $STAMP /tmp/flagfile

#----find older files
find /start/dir -type f ! -newer /tmp/flagfile -print |\
while read FILE
do
  : something with $FILE
done

# 7  
Old 06-26-2008
Quote:
Originally Posted by kennylcn
> sh -x test5.sh
test5.sh: syntax error at line 3: `STAMP=$' unexpected

I think I got the perl but dont know whats happen.
You are feeding a korn shell script into a bourne shell. That won't work. You should do:
chmod u+x test5.sh
./test5.sh
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find a file that's modified more than 2 days ago but less than 5 days ago?

How to find a file that's modified more than 2 days ago but was modified less than 5 days ago by use of any Linux utility ? (4 Replies)
Discussion started by: abdulbadii
4 Replies

2. Shell Programming and Scripting

Grep from file modified one minute ago

Hello, I have a list of files, an example below: -rw-r--r-- 1 smf_oper esg 910773 Jul 6 12:52 am1slc02_ACS_201607061242571_20346.cdr -rw-r--r-- 1 smf_oper esg 995838 Jul 6 12:52 am1slc01_ACS_201607061243125_19895.cdr -rw-r--r-- 1 smf_oper esg 557235 Jul 6 12:52... (5 Replies)
Discussion started by: nms
5 Replies

3. Shell Programming and Scripting

Check how many minutes ago the last file created

Hi , I need help in getting how many minutes ago the last file, matching some pattern in file name, was created in a folder. Thanks in advance. (8 Replies)
Discussion started by: Anupam_Halder
8 Replies

4. Shell Programming and Scripting

Find a string in file 5 days ago

Hi, I need to grep for a string "Color Yellow" in all log files dated 5 days back until today's date . So, as today is 20 Dec i need to find in all logs from 16th dec to 20 dec. Also, i need ls -ltre output for the files that have the "Collor Yellow" string. Below is my OS: ... (1 Reply)
Discussion started by: mohtashims
1 Replies

5. Shell Programming and Scripting

Help - compress file one day ago

Hi All, I'm a new member of this Forum. I have need your help to handle this request. "Compress a file name not of today but of yesterday only". For example 0 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.xls 20 mar 08:00 TEST_RPT_STATUS_M1I_CMI20120320.rep 21 mar 08:00... (6 Replies)
Discussion started by: gio123bgg
6 Replies

6. Shell Programming and Scripting

Find unix file created how many days ago?

i want to find unix file created how many days ago? (4 Replies)
Discussion started by: utoptas
4 Replies

7. Shell Programming and Scripting

Touch New File with First Line

I am interested in creating a new file from a KSH script where the first line is printed. I know how to create the file, but creating with a pre-defined first line is what I need help with. My code below creates the file, but how do I accomplish that and do it so that when I open that txt file... (5 Replies)
Discussion started by: royarellano
5 Replies

8. 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

9. Shell Programming and Scripting

Find the file from 15 days ago

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (2 Replies)
Discussion started by: YoungBlood
2 Replies

10. UNIX for Dummies Questions & Answers

file was created before 15 days ago.

How can I get difference date between today and 15 days ago and all filename is was created before 15 days ago? It has to be korn shell script. Thanks. (1 Reply)
Discussion started by: YoungBlood
1 Replies
Login or Register to Ask a Question