Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

event that run a batch or a command???? 1

Status
Not open for further replies.

surfguy

Technical User
May 4, 2007
14
IT
HI Guys,

Here is the problem:

I need a way, a command a batch a demon or (if exist) a
commercial product, that when a file is copied in a
folder, it reconize the event and let run a command form
command line.

I hoper that i was clear enought in the explanation, and
that someone can help me :)

Have a nice day,
Riccardo

 
Hi Riccardo. You could use cron to do this - perhaps a script to run every few minutes to check for the existence of a new file, running (or not) the necessary command (script?) as required. Does the new file have a unique name or does it have a date/time element for example?

I want to be good, is that not enough?
 
KenCunningham is right! that's the easiest way to do that!

In fact we use the same concept for our developers' forms when they need to compile them! all they need to do is to copy the form to a directory which will be triggered by a crontab job to compile the new forms!

Regards,
Khalid
 
Hi Guys,

Thanks for your Idea, i thought about it,
but i have those file copied in a lot of directories, arouns 200, one of reach user, and i don't know when the user will put the file, this means that on crontab i have to set a short time, for example chek every 60 seconds, but 60 sec for 200 directories, maybe can slow down System performances, on the server i have other proces runnig, and a database.

What do you think? this kind of check can be expensive, talking about performances?

thanks,
Riccardo
 
ok, how do they copy to the directories? are they using the command cp?

If so then you can write your own cp (which will call the actual cp after doing the notification you need!) and you can include this cp to their path in the .profile!

Regards,
Khalid
 
HI khalidaaa

This look interesting, and wich kind of notification can
i do in order to let run a batch or a command?

Regards,
Riccardo
 
I didn't get what you mean?

You can do any kind of notification!? you can write to a log which you will check later! or you can email to an account! or you can run another script inside your custom cp script! You can do any thing! and you can run a batch job or another command within the custom cp you wrote!

Regards,
Khalid
 
HI khalidaaa,

It looks interesting, now the reason why i was looking the creation of a file in a directory to start a command is that, i would run a commad in a AIX server, but this command as to be send froma aweb page, so the Idea is the following:

Via web i do a "cp" or a "pcp" to the Aix Box, this "cp" or "pcp" will be the one modified by myself, and this will include the command that i want to perform, right? is that the way you suggested?

Regards,
Riccardo

 
exactly

That's what i meant

Try it and keep us posted with your progress!

Regards,
Khalid
 
hi khalidaaa,

Now i have a question, how can i customise a command?
do you have any link?

Thanks a lot
RIccardo
 
ok I think your case is simple coz you run the cp from a web so you have control on exactly which cp to run!

First of all you go to a directory that you must keep for this specified custom commands that you will create (let's say cd /Riccardo/custom

Then you start to write your won cp by doing this:

vi cp

Code:
# You need first to make sure that the destination you are copying to is the right one

if [[ $2 = "/home/user1" ]]
then
# here you specify the action you need (say email to root)
mail -s "cp to $2" root < echo "Copying to $2"

# then you have to call the actual cp command
/usr/bin/cp $1 $2

fi

chmod +x cp

After completing from the above script you need to include the script in the user path! Make sure you put the script before /usr/bin in the PATH in .profile for each user to be monitored for copying.

that's all you need to do! The only thing that you need to include is a way to get the options of the cp command! Like for the above example any thing like this will work:

cp /tmp/123 /home/user1

But if you have options with cp then the above will get complicated and won't work

cp -pk /tmp/123 /home/user1

in this case i think there is a command called getops that you can use inside your script to get the options of the command (just to make your script smarter

But in your case i think you know exactly what is the options with the cp cause you run the cp from a web page right? if so then you have to include that in your script!

I hope this is clear enough?

Regards,
Khalid
 
Hi Khalid,

What you wrote sound clear, just a question, i typed

"man cp", for see more info about it, but i don't se option for "cp" to a different server, i don't see option for Ip address, username and password.
How can i "cp" from different machines?

Regards,
Riccardo
 
You can use rcp or scp!

man rcp

man scp

for the rcp you need to configure .rhosts in the destination machine

for the scp you need to do more work configuring ssh! so i advice you to go for rcp (unless you want encryption for your copy!)

Regards,
Khalid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top