06-10-2009
Quote:
Originally Posted by
KevinADC
Well, it is your task, so what have you tried?
THis is my file named mycron which I add it to the crontab entry later to run every 5 mins and this works. But I havnt done the last part - to run another script if everything succeeds.
Thanks for the reply Yogesh. But in ur code, what if the mv fails - ie, say the destination directory doesnt exist or something else ... only after all this succeeds I need to start another script.
#
# Taking action if a particular file appears in a dir
#
filename="/home/mrudula/myfile"
count=`find "$filename" | wc -l`
if [ "$count" -eq 1 ]
then
# Renaming filename
new_filename="$filename".new
mv $filename $new_filename
echo "$filename" renamed to "$new_filename"
# Moving to backup directory
bkup_dir="$filename"-bckup
mkdir "$bkup_dir"
mv "$new_filename" "$bkup_dir/$(basename $new_filename)"
echo "$new_filename" moved to "$bkup_dir"
else
echo "No file found - "$filename""
fi
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I need some assistance with comparing 2 diff application. The format of the first file is in TAR "filename.1.2.3.tar" . The second file is a running application for which i need to find the version and then prompt the user for action as below :-
Once compared, It needs to prompt the user,... (0 Replies)
Discussion started by: systemali
0 Replies
2. Shell Programming and Scripting
What one finds challenging another finds simple...
(HPUX B.11.11)
I have a text file named something like 12345.dst that could look like this:
DOG
CAT
NONE
TEST
CAT
What I want to end up with is 12345.dst looking like this:
CAT
DOG
TEST
removing "NONE" should it be there and... (1 Reply)
Discussion started by: djp
1 Replies
3. Shell Programming and Scripting
Hello,
I have a script that monitors files uploaded via ftp. After a successful upload, the file name is written to the pipe.
There is another program that reads this pipe and allows automatically run any program or script ( say test.sh ) to process the newly uploaded file.
cat test.sh... (2 Replies)
Discussion started by: fed.linuxgossip
2 Replies
4. Shell Programming and Scripting
Hello,
I'm writing a script that will automate the launch of some services on my AIX machine. However, some services are dependent on the successful startup of others. When I start these services manually, I usually just check a log file until I see a message that confirms a successful... (3 Replies)
Discussion started by: pallak7
3 Replies
5. Shell Programming and Scripting
I want the script to read the directory I am running the script from and print the contents of any file that has GX in it's title. This is the code needed. But how do I combine it?
#!/usr/bin/perl
opendir(CURRENT,".");
@list = readdir(CURRENT);
closedir(CURRENT);
foreach $item (@list){... (4 Replies)
Discussion started by: DemonixX
4 Replies
6. Shell Programming and Scripting
shell: #!/bin/ash
I searched and found a few relevant posts (here and here - both by porter, on the same day (?)) however both are just a do while loop, I need to check a file date and compare it to the current time.
I would like it to say if file 'test' is more than 12 hours old than "right... (3 Replies)
Discussion started by: phdeez
3 Replies
7. UNIX for Dummies Questions & Answers
Hi Experts,
I have a file which contains some text. i need to print the word next to a given keyword. Please help.
Ex: test.txt
=====================
NEXT HOST
=====================
AEADBAS001
access-list 1 permit xxxxxxxxxxxxxx
ip access-list extended BLA_Outgoing_Filter... (6 Replies)
Discussion started by: mwrg
6 Replies
8. Shell Programming and Scripting
Hi All,
I am very new to this forum and beginner to shell scripting.
I need a shell script to:
Search for a text in XML file à if the same text appears twice in an XML file à output file name
Script should loop thru every xml file of a given folder.
Please help me writing this script.
... (1 Reply)
Discussion started by: amardeep001
1 Replies
9. Shell Programming and Scripting
Hi All,
I want to read all lines after a perticular string {SET UP VALUES}apprears in the file.
SET UP values contains direcory, number of days and file type.
Step1: Read all lines below SET UP VALUES string.
Step2: If set up values are not present in each record then read from default... (4 Replies)
Discussion started by: Nagaraja Akkiva
4 Replies
10. UNIX for Beginners Questions & Answers
Have some files in /tmp/dir
abc.zip
123.zip
345.zip
and if name matches to 345.zip then take action
My code....
am i doing something wrong ? Please advise.
#!/bin/bash
set -x
cd /tmp/dir
for i in *.*
do
if ]
then (4 Replies)
Discussion started by: abhaydas
4 Replies
LEARN ABOUT PHP
eio_rename
EIO_RENAME(3) 1 EIO_RENAME(3)
eio_rename - Change the name or location of a file.
SYNOPSIS
resource eio_rename (string $path, string $new_path, [int $pri = EIO_PRI_DEFAULT], [callable $callback = NULL], [mixed $data = NULL])
DESCRIPTION
eio_rename(3) renames or moves a file to new location.
PARAMETERS
o $path
- Source path
o $new_path
- Target path
o $pri
-The request priority: EIO_PRI_DEFAULT, EIO_PRI_MIN, EIO_PRI_MAX, or NULL. If NULL passed, $pri internally is set to
EIO_PRI_DEFAULT.
o $callback
-$callback function is called when the request is done. It should match the following prototype:
void callback(mixed $data, int $result[, resource $req]);
o $data
-is custom data passed to the request.
o $result
-request-specific result value; basically, the value returned by corresponding system call.
o $req
-is optional request resource which can be used with functions like eio_get_last_error(3)
o $data
- Arbitrary variable passed to $callback.
RETURN VALUES
eio_rename(3) returns request resource on success or FALSE on error.
EXAMPLES
Example #1
eio_rename(3) example
<?php
$filename = dirname(__FILE__)."/eio-temp-file.dat";
touch($filename);
$new_filename = dirname(__FILE__)."/eio-temp-file-new.dat";
function my_rename_cb($data, $result) {
global $filename, $new_filename;
if ($result == 0 && !file_exists($filename) && file_exists($new_filename)) {
@unlink($new_filename);
echo "eio_rename_ok";
} else {
@unlink($filename);
}
}
eio_rename($filename, $new_filename, EIO_PRI_DEFAULT, "my_rename_cb", $filename);
eio_event_loop();
?>
The above example will output something similar to:
eio_rename_ok
PHP Documentation Group EIO_RENAME(3)