Beginner trying to write a shell script!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Beginner trying to write a shell script!
# 1  
Old 08-19-2002
Beginner trying to write a shell script!

Dear All,

I'm trying to write a shell script that continously checks a certain folder. When a file is placed in the directory securely copies the file to another server.

I've got the secure copying working, but I don't know how to contiously check a directory for a new file and then use that file to scp.

(The files contain a date & timestamp within the file name)

Any ideas???

Thanks,

A Complete Novice
# 2  
Old 08-19-2002
One way would be to use cron. Check the man page for crontab and cron. Set your script to run every minute of every day.

If that isn't good enough, then you would have to check out inittab - this could start your process and if it died, restart it. Then inside your script you would have to loop (along with a sleep command - to wait say 10 seconds and then check the directory for files, if there are files, move them, loop to wait)

Scripting is only putting into a file what you would do manually - the only hard part is getting the logic of things you do without realizing it ( like listing a directory and not moving or deleting certain files).
# 3  
Old 08-19-2002
Here is one possible solution:

Code:
while true; do
  sleep 1
  if [ -f /path/to/some/file ]; then
    # Take some action
  fi
done

After reading RTM's post, you might want to up the time to 10 seconds, or 60 seconds or whatever is reasonable. 1 second is probably to tight of a loop.
# 4  
Old 08-19-2002
Tools Some options

You can start a script from the cron e.g. every 1 minute or you write a script with is running for ever with a sleep in it (eg. sleep 60, means a sleep for 60 sec).

eg.


#!/bin/csh
foreach FILE (`find /<your path>/ -newer LastCheck -print`)
scp /<your path>/ $FILE /<new path>/$file
...... maybe some more code ......
end

touch LastCheck

exit


To initialize this way you need to create the 'LastCheck' the first time by hand by `touch LastCheck`

every time you run this script it copies all files who are newer then the file LAstCheck to the new location

See also the find man page:
http://docs.sun.com/?q=find&p=/doc/8...9vek55d&a=view
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Beginner bash - basic shell script 'while' help...

Hi everyone, first time visitor to these forums here. Keeping a long story short I've been attempting to learn how to code in bash. I have VERY little previous experience with coding languages besides simply copying and pasting batch scripts for Windows. So, with that in mind I've followed a... (4 Replies)
Discussion started by: Meta
4 Replies

2. Shell Programming and Scripting

If condition shell script beginner

Hi all I have the folloing process that needs checking often: ps -ef | grep ih bscsrtx 206 15901 0 11:28:10 pts/6 0:00 fih -r4 bscsrtx 218 15901 0 11:28:27 pts/6 0:01 aih bscsrtx 29763 15901 4 11:27:16 pts/6 0:59 rdh -prih root 429 27268 0 11:30:15 pts/td ... (13 Replies)
Discussion started by: fretagi
13 Replies

3. Shell Programming and Scripting

How to write config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

4. UNIX for Dummies Questions & Answers

How to write Config shell script to pass variables in master shell script?

Dear Unix gurus, We have a config shell script file which has 30 variables which needs to be passed to master unix shell script that invokes oracle database sessions. So those 30 variables need to go through the database sessions (They are inputs) via a shell script. one of the variable name... (1 Reply)
Discussion started by: dba1981
1 Replies

5. Homework & Coursework Questions

Shell Script (beginner)

1. The problem statement, all variables and given/known data: Arguments: http://farm9.staticflickr.com/8070/8212131370_8b6e8c10c5_c.jpg I am given these three arguments. $1, $2, $3 The first argument is the path to a directory. So, how would I go into the directory and compare files? I... (5 Replies)
Discussion started by: spider-man
5 Replies

6. Homework & Coursework Questions

Shell-script loops beginner

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: "Create a shell script that changes the selected word to another word in all files from selected archive. The... (1 Reply)
Discussion started by: oibanuelos
1 Replies

7. Shell Programming and Scripting

Shell script (beginner) need help...

Hello, I'm new to Sheel script and I need your help for a script I need to develop (for me). Indead, I have a software which log all entry from internet and save it in text file. But, the log is practically unreadable because every 256 characters jump to a new line (even if the message is... (5 Replies)
Discussion started by: acidoangel
5 Replies

8. Shell Programming and Scripting

Debugging a beginner shell script...

I have been following a tutorial on bash which has proven to be very helpful. However, i am stuck with a command not found issue when asking for a y/n response from the user. Below is the part of code I believe is giving me grief... I have been trying to work through this for 3 hours now.... Please... (5 Replies)
Discussion started by: brokepunk
5 Replies

9. Shell Programming and Scripting

Beginner shell script help

. ./testFile.sh url=http://ichart.finance.yahoo.com/table.csv?s= suf=&d=5&e=9&f=2009&g=d&a=1&b=4&c=1999&ignore=.csv wget $url$s1$suf; sleep 10; cat header.txt > $s1.txt; chmod 777 $s1.txt; sed '1d' table.csv?s\=$s1 >> $s1.txt; rm -Rf table* Very new at shell scripting as you can see... (3 Replies)
Discussion started by: harte
3 Replies

10. Shell Programming and Scripting

Shell Script for Beginner

I have a folder with lots of file. e.g. a.txt, b.txt, c.txt.... I want to put these files from the source directory and place them in a destination directory in a specific order, such as /destination/a/a.txt, /destination/b/b.txt, /destination/c/c.txt, ...... Please help. Thx :confused: (3 Replies)
Discussion started by: aaron_fong
3 Replies
Login or Register to Ask a Question