Find & move script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find & move script
# 1  
Old 06-27-2012
Find & move script

Hi all

I wrote a little script that search for a file and moves it, its like this:

Code:
#!/bin/ksh

today=`date +"%d_%m_%y"`

if [ -f $1 ];

 then
 mkdir -p /tmp/bigfiles/$today
 mv $1 /tmp/bigfiles/$today/
 echo "moving big file from /home/appcwec " | mailx -s "bigfile" ffff@yyy.com


else

echo "big file in /home/appcwec does not exist" | mailx -s "bigfile" ffff@yyy.com

fi

It does work normaly,

But if I put in the crontab like this:

Code:
0 17 * * * /home/appcwec/ksh check_file.ksh 1.tmp

It does not work.

Can you help?

FR
# 2  
Old 06-27-2012
provide the absolute path of 1.tmp

Code:
0 17 * * * /home/appcwec/ksh check_file.ksh /absolute/path/of/1.tmp

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 06-27-2012
Try with this .. Assign shell to execute and provide full path of 1.tmp ..
Code:
0 17 * * * ksh /home/appcwec/ksh check_file.ksh /full/path/of/1.tmp

# 4  
Old 06-27-2012
find & move script

Ok, did work fine, out of crontab, but what happens if test argument or the filename changes from :

Code:
t.tmp

to
Code:
2.tmp

# 5  
Old 06-27-2012
If your file name happens to change frequently then you have re-write the code to take the argument from a seperate static file.

Code:
#!/bin/ksh

today=`date +"%d_%m_%y"`

while read FILE
do
if [ -f $FILE ];

 then
 mkdir -p /tmp/bigfiles/$today
 mv $FILE /tmp/bigfiles/$today/
 echo "moving big file from /home/appcwec " | mailx -s "bigfile" ffff@yyy.com


else

echo "big file in /home/appcwec does not exist" | mailx -s "bigfile" ffff@yyy.com

fi
done < "/your/static/file"

Now if your filename to be moved changes, then you have to just update the name in your static file. In this static file you can also include multiple filenames on seperate lines.
This User Gave Thanks to vikasghavate For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Move & Sort by Name - Kick out Bad File Names & More

I have a dilemma, we have users who are copying files to "directory 1." These images have file names which include the year it was taken. I need to put together a script to do the following: Examine the file naming convention, ensuring it's the proper format (e.g. test-1983_filename-123.tif)... (8 Replies)
Discussion started by: Nvizn
8 Replies

2. Shell Programming and Scripting

Script to find string & email

Hi I have a query that some of you may be able to help me with if poss? I'd appreciate it very much. I've got a few log files, that I would like to search for a string. When the string is found, i'd then like to email out the line/sting. If not found, i'd like to email out 'no found'... (2 Replies)
Discussion started by: horhif
2 Replies

3. Programming

Script for creating a directory & move the .tif files in it.

Hi Team, I have thousands of TIF files which are converted from PDF. Below is a sample of it. LH9406_BLANCARAMOS_2012041812103210320001.tif LH9406_BLANCARAMOS_2012041812103210320002.tif LH9406_BLANCARAMOS_2012041812103210320003.tif LH9411_ANGENIAHUTCHINSON_2012041812102510250001.tif... (9 Replies)
Discussion started by: paragnehete
9 Replies

4. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

5. Linux

Create folder by script & move files in it

Hi Team, I have over 1 lakh pdf files. I want to create folders like Disk-1, Disk-2 ..... & want to move 3000 pdfs per folder. Can i do it by script? Please help me. Thanks & Regards Parag Nehete (4 Replies)
Discussion started by: paragnehete
4 Replies

6. Shell Programming and Scripting

Perl Script to find & copy words from Web.

I need to write a perl script to search for a specific set of numbers that occur after a series of words but before another. Specifically, I need to locate the phrase today at the summit, then immediately prior to the words tonnes/day copy the number that will be between 100 and 9,999, for example,... (1 Reply)
Discussion started by: libertyforall
1 Replies

7. UNIX for Dummies Questions & Answers

sample script to archive & move previous day syslog files

hi all. Please help me with archiving previous day syslog files. the files have no extension and have the format YYYY-MM-DD. I want to archive the file then move it to some other machine. thanks. (2 Replies)
Discussion started by: coolatt
2 Replies

8. Solaris

Find & read a script in Unix

Hi, Please give me the cmd to find the location of a script(eg. xyz_bkup.sh).also i want to read the contents of the script. Thanks in advance James (8 Replies)
Discussion started by: James777
8 Replies

9. Shell Programming and Scripting

Find, Append, Move & Rename Multiple Files

Using a bash script, I need to find all files in a folder "except" the newest file. Then I need to insert the contents of one text file into all the files found. This text needs to be placed at the beginning of each file and needs a blank line between it and the current contents of the file. Then I... (5 Replies)
Discussion started by: Trapper
5 Replies

10. UNIX for Dummies Questions & Answers

improving my script (find & replace)

Hi all, I have a script that scan files, find old templet and replace it with new one. #!/bin/ksh file_name=$1 old_templet=$2 new_templet=$3 # Loop through every file like this for file in file_name do cat $file | sed "s/old_templet/new_templet/g" > $file.new #do a global searce and... (8 Replies)
Discussion started by: amir_yosha
8 Replies
Login or Register to Ask a Question