script set up required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script set up required
# 8  
Old 10-20-2011
Quote:
Originally Posted by zaxxon
Should be more like this:
Code:
#!/bin/sh

while read DAYS INDIR OUTDIR
do
     find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done < tar_config2

readCan take parameters itself which are separated by blank(s) (Defined through IFS in the shell). So awk is not needed here to fill the variables.
I am not sure what is the difference between those 2 files tar_config2 and /home/499633/scripts/tar_config_file.sh though.

To make a dry run you could add a echo in front of the find command (maybe add some escapes to avoid errors).

Hi Zaxxon,

well Sorry there is only one file tar_config2.sh which contain the configuration details ...below are the details

Quote:
10 /home/499633/files /home/499633/output
so if I try your code as guided by you

Quote:
#!/bin/sh

while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done < tar_config2
will it work..?
# 9  
Old 10-20-2011
Yes it will.. Modified input file to while loop ..
Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done < tar_config2.sh

# 10  
Old 10-20-2011
@suchitasinha123:

Just to not mess up each post, you do not have to quote every former post. That is not needed as we can see and read them actually and don't need a copy inside your new posts.

Also for code, use code tags, not quotes. Quotes are just for quoting somebody. When you write code, then use code tags like [code] for the beginning and [/code] to end the code, data or logs, thanks.

Also you can try out the code we handed over. You can also just set up some dummy directory with files to test the code, as well as you can add an echo in front of the actual find command, so nothing harmful will happen.
# 11  
Old 10-20-2011
Question How to overcome from this error

Quote:
Originally Posted by jayan_jay
Yes it will.. Modified input file to while loop ..
Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done < tar_config2.sh

Hi Jayan,

thanks a lot ,well I have a folder named scripts(\home\Administrator\scripts) in which all files(tar_config-file1.sh and main1.sh ) are kept. so now main1.sh wil read the properties from tar_config-file.sh and as per that it will do the logic ...and there is input folder from where the files will be selected and the output folder where the files will be moved

the contents of the tar_config_file1.sh are
*********************************
Code:
10 /home/Administrator/files /home/Administrator/output

the contents of the main1.sh are
******************************
Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done </home/Administrator/scripts/tar_config_file1.sh

Now upon executing main1.sh, I get the error that

main1.sh syntax error near unexpected token 'done'.please guide me how to corret this problemSmilie
# 12  
Old 10-20-2011
Quote:
Originally Posted by suchitasinha123
Code:
#!/bin/sh
while read DAYS INDIR OUTDIR
do
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;
done </home/Administrator/scripts/tar_config_file1.sh

Now upon executing main1.sh, I get the error that

main1.sh syntax error near unexpected token 'done'.please guide me how to corret this problemSmilie
Make sure your script contains only Unix-style end-of-line characters.

Code:
cat -vet main1.sh

You should only see

Code:
#!/bin/sh$
while read DAYS INDIR OUTDIR$
do$
find $INDIR -type f "!" -mtime $DAYS -exec mv {} $OUTDIR \;$

If there are any
Code:
^M

characters in there you will need to remove them by doing

Code:
tr -d '\r' < main1.sh > main1.sh.new
mv main1.sh.new main1.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Not able to get the required o/p from my script

Hi Experts, I have a script as below : # cat a.sh var=`mysql -usupport -p'testing' -e "select count(1) from db_test.sampletable;"` echo $var the output of this script is : count(1) 145039 Now i want to remove header from my o/p and modify somewhat like 145039 I have... (9 Replies)
Discussion started by: mukulverma2408
9 Replies

2. Shell Programming and Scripting

Help needed with shell script to search and replace a set of strings among the set of files

Hi, I am looking for a shell script which serves the below purpose. Please find below the algorithm for the same and any help on this would be highly appreciated. 1)set of strings need to be replaced among set of files(directory may contain different types of files) 2)It should search for... (10 Replies)
Discussion started by: Amulya
10 Replies

3. HP-UX

Sudo entry required to set permission similar to ROOT without using password (PASSWD) change optio

Hi All I had installed sudo in HP UX 11.3 and it is working fine but not able to make entry required to set permission similar to ROOT without using password (PASSWD) change option for define user in /etc/sudoers file Please help if some know the syntex? :confused::wall: (2 Replies)
Discussion started by: deviltech
2 Replies

4. UNIX for Dummies Questions & Answers

Perl Script:how to find how many parameters are required to run the script

How to find how many parameters are required to run a Perl script? (1 Reply)
Discussion started by: Lakshman_Gupta
1 Replies

5. Shell Programming and Scripting

Script required

Hey All, I am seeking for the script which will do as follows, 1) Login on one Unix server "Server1" 2) Want to access other Unix server "Server2", and want to get the information as, on one go. df -k /tmp df -k / df -k "any file system" 3) Re-direct the output to "space.txt" on... (12 Replies)
Discussion started by: ravinderkodan88
12 Replies

6. Shell Programming and Scripting

Help required to get a script

Hi Experts, I am very beginner in Bash Shell Scripting. Can anyone please guide me to create a script which should show the most busy file systems in sort basis as there are a lot of file systems on the server. I was told this task to be done by my IT lead and I must have to do this in... (3 Replies)
Discussion started by: naw_deepak
3 Replies

7. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

8. Shell Programming and Scripting

Script required

Hi All, I have file nodes.txt that contains node names one by one. I'm running the following command. /opt/OV/bin/ovet_topodump.ovpl -nodeif <nodename> -detail Field <nodename> should take (replace) the node names from the nodes.txt one by one till last node. Pls. give me script for... (1 Reply)
Discussion started by: ntgobinath
1 Replies
Login or Register to Ask a Question