scripting help with touch and sed


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scripting help with touch and sed
# 8  
Old 02-14-2005
To keep it going, you can put the whole thing within a while
loop, and get rid of the "exit" when it doesn't find a file.

Here is a good shell scripting web page, and the specific page
with the while loop:

http://www.scit.wlv.ac.uk/~jphb/spos...ell.index.html
http://www.scit.wlv.ac.uk/~jphb/spos...ll/shell7.html


as for getting rid of the ./
There is probably a hardcore, regular expression guru way to do it,
but here is an easier way i found:

echo "./Gtest" | sed -e 's/G//g' | cut -c3-


come to think of it, you probably don't even need sed.
you might be able to just use:
cut -c4-

My motto is to avoid complicated regular expressions
unless I CANNOT find a better and easier way. Smilie
# 9  
Old 02-14-2005
temp...

You shoudln't need the temp.
I only put it there to point out that you have to be getting
the filename from standard output somewhere.

That pipe you did should be alright.
# 10  
Old 02-14-2005
Thank you!
# 11  
Old 02-15-2005
gjduff, you still there? I'm trying to make the script check every 10 seconds for a new file then update a logfile. Can you see what I'm missing?

Thanks,
alexkav

#!/bin/ksh

LOGFILE=logs/gfiupload.log
NEW=`find . -type f -name "G*" -newer newtime`

while true; do
if
[ -z $NEW ]; then
echo "bombing..." >>$LOGFILE
touch newtime
sleep 10

else
FILE=`echo $NEW | sed -e 's/G//g'`
echo `date +%m%d%Y_%H:%M`: New file found: $FILE >>$LOGFILE
mv newtime oldtime
touch newtime
fi
sleep 10
done
# 12  
Old 02-15-2005
I'll check

Looking at the code, I don't immediately see the problem.
I'll have to grab the code and try it out for myself.

I gather you are running it in the background? (not that
this necessarily matters)

Anyways, I've got a fairly busy day, but I'll try and get back to
you ASAP.
# 13  
Old 02-15-2005
hmm

Oh, wait a sec.

before I attempt any debugging, I'll point out that possibly 10 seconds
is too short of a time for one of those G* files to actually get a timestamp on
them that is newer than the "newtime". (the file timestamps seem to be to the minute
on my machine)

Due to that, Possibly, you should only "touch newtime"
if a new file, is found. When it is bombing, maybe don't do it.
# 14  
Old 02-15-2005
sorry

I should have tried it before opening my mouth.
anyways, this works:

Code:
#!/bin/ksh

LOGFILE=logs/gfiupload.log


while true; do

NEW=`find . -type f -name "G*" -newer newtime`

#echo "here"
#echo $NEW

if [ -z $NEW ]; then
	echo "bombing..." >>$LOGFILE
	#touch newtime
	sleep 10

else
	FILE=`echo $NEW | sed -e 's/G//g'`
	echo `date +%m%d%Y_%H:%M`: New file found: $FILE >>$LOGFILE
	mv newtime oldtime
	touch newtime
fi

sleep 10
done

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help shell scripting using awk or sed or other

I need to create a script to change a file depending of 3 conditions using a target as parameter... first condition <chamada> <numeroTerminalOriginador>CALLER</numeroTerminalOriginador> <imeiOriginador></imeiOriginador> <cgiPrimeiraErbOriginador></cgiPrimeiraErbOriginador>... (2 Replies)
Discussion started by: poulis
2 Replies

2. Shell Programming and Scripting

Need help with awk and sed scripting

I need help with sed and awk scripts to search for Symmetrix ID=000090009902 and then grep its child disk devices associated to the dead paths and display them only, so that those dead devices can be removed. test01:/#powermt display dev=all Pseudo name=hdiskpower0 Symmetrix ID=000090009902... (4 Replies)
Discussion started by: aix_admin_007
4 Replies

3. Shell Programming and Scripting

Need help with sed scripting

Hi expert, i need URGENT help in bash shell scripting using sed: i woud like to search for the word XMLRPC which is at theend of the line below in up2date file. Once found or match serverURL=https://redhat.com/XMLRPC replace with myserver.com like this ... (1 Reply)
Discussion started by: lamoul
1 Replies

4. Shell Programming and Scripting

Sed scripting issue

Hi all! I was wondering if anyone could help suggest some solutions to an issue i'm having using the Sed command. I'm still a relative novice at this, but slowly learning and enjoying the power of batch processing. I am using Sed to extract values from a .txt file containing hundreds of... (2 Replies)
Discussion started by: StudentFitz
2 Replies

5. Shell Programming and Scripting

Shell Scripting -- sed

Hi, In one of my scripts, I am using sed to do an expression replacement. The code in the script is as under sed "s|MY_INP_Lab=""|MY_INP_Lab="${2}"|" file1, where $2=xyz_abc_mbk The EXPECTED output is in file1, all the instances ofMY_INP_Lab="" shall be replaced by... (2 Replies)
Discussion started by: vivekmattar
2 Replies

6. Shell Programming and Scripting

sed scripting help need

hi all, i want to display output of sar, whichever idle time is less than 30%..i want to add HI and BYE at the starting and ending of the line. For an example: sar Linux 2.6.9-78.0.1.ELsmp (hostname) 07/10/2009 07:10:01 AM CPU %user %nice %system %iowait %idle... (7 Replies)
Discussion started by: raghur77
7 Replies

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

8. Shell Programming and Scripting

SED scripting select

Say I have a file 'example.txt' with these lines of code in it: hello:anddasd:cheese:gerg whatever:sdadsa:asdfasdfa:wwew hmmmm:something:gfhfhgf:sdasdas Question: 1. How would I write a script which is able to take all the words before the first ':'? 2. How would I write a script which is... (6 Replies)
Discussion started by: i_am_a_robot
6 Replies

9. Shell Programming and Scripting

scripting with awk and sed

hey all, i was just wondering if it was possible to to get data from user input , and parse it through sed to remove or add what that user has entered into a flat file? do i need awk ? any help is greatly appreciated ~shan2on (2 Replies)
Discussion started by: shan2on
2 Replies

10. Shell Programming and Scripting

Help on SED AWK in shell scripting

Hi, I have a script abc.sql which contains a word 'timestamp'. I have another script xyz.txt genrated everyweek, which has a new timestamp value every week. How do I replace the word 'timestamp' in script abc.sql with the value mentioned in the script xyz.txt, so that I can run the script... (3 Replies)
Discussion started by: kaushys
3 Replies
Login or Register to Ask a Question