script set up required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting script set up required
# 1  
Old 10-19-2011
Wrench script set up required

Hi,

I have a configuration file name (tar_config2.sh)which has the following enteries ....

Quote:
10 /home/admin/files /home/admin/output
here
10 represents days(mofification time),
/home/admin/files represents source folder from where the files will be picked up
/home/admin/output represents whwre the files will be kept so it is a sort of destination


I was planning to move files as per the modification time (10 days) from the source folder(files) location to the destination (output),I want my main script file should read my this configuration file(tar_config2.sh) and take parameters from that...could you please suggest me what will be the command inside my main script file..?

Last edited by suchitasinha123; 10-19-2011 at 01:48 PM.. Reason: just little bit logic was revised
# 2  
Old 10-19-2011
read that config file with a while loop and have it do the things inside, that you need. Maybe combine it with a find and the -mtime switch to check the date. To move files, you can use the mv command. That should be sufficient to get some tries going.
# 3  
Old 10-20-2011
wrtitng that main script file to read the contents from the configuration file

Quote:
Hi,

I have a configuration file name (tar_config2.sh)which has the following enteries ....

Quote:
10 /home/admin/files /home/admin/output
here
10 represents days(mofification time),
/home/admin/files represents source folder from where the files will be picked up
/home/admin/output represents whwre the files will be kept so it is a sort of destination


I was planning to move files as per the modification time (10 days) from the source folder(files) location to the destination (output),I want my main script file should read my this configuration file(tar_config2.sh) and take parameters from that...could you please suggest me what will be the command inside my main script file..?




Quote:
Originally Posted by zaxxon
read that config file with a while loop and have it do the things inside, that you need. Maybe combine it with a find and the -mtime switch to check the date. To move files, you can use the mv command. That should be sufficient to get some tries going.
Hi,

Thanks a lot for the explnation but still not able to grasp that much , I request you if you can you show by writing that script that will read the configuration files as discussed above...it will help me in clearing my understanding..!!
# 4  
Old 10-20-2011
We are ready to help Smilie .. Please come up with the code what you have tried .. We will assist you further with that..
# 5  
Old 10-20-2011
But when I write it, you will have no more work to do?! Smilie

Code:
while read A B C; do
     # ... do something with A
     # ... do something with B
     # ... do something with C
done < configfile

Try it out yourself. Making errors and doing corrections will make you learn. There is also plenty of shell scripting tutorials. Googling for "shell while read" will show you tons of sites with examples like this. Don't be lazy! Smilie Smilie
I mean if you get really stuck don't hesitate to ask, but a little bit of work on your side should be ok. Agreed?
This User Gave Thanks to zaxxon For This Post:
# 6  
Old 10-20-2011
please guide on this script

I have written main script file name main1.sh which will read this configuration file ...

Quote:
#!/bin/sh

while read line
do
configurabledays=`awk '{print $1}' tar_config2`
input_dir=`awk '{print $2}' tar_config2`
out_dir=`awk '{print $3}' tar_config2

find $inp_dir -type f "!" -mtime $configurabledays -exec mv '{}' $out_dir
done </home/499633/scripts/tar_config_file.sh
Well any changes perhaps need to be made plz guide me on that..!!Smilie

---------- Post updated at 03:02 AM ---------- Previous update was at 02:58 AM ----------

Quote:
Originally Posted by jayan_jay
We are ready to help Smilie .. Please come up with the code what you have tried .. We will assist you further with that..
Hi ,

Thanks Jayan ,I have written the main script file (main1.sh) below are the contents of it...


Quote:
#!/bin/sh

while read line
do
configurabledays=`awk '{print $1}' tar_config2`
input_dir=`awk '{print $2}' tar_config2`
out_dir=`awk '{print $3}' tar_config2`

find $inp_dir -type f "!" -mtime $configurabledays -exec mv '{}' $out_dir
done </home/499633/scripts/tar_config_file.sh
Well any changes perhaps need to be made plz guide me on that..!!

Last edited by zaxxon; 10-20-2011 at 05:07 AM.. Reason: cutting out the quote of all the posts before, was messy
# 7  
Old 10-20-2011
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).

Last edited by zaxxon; 10-20-2011 at 05:43 AM.. Reason: spelling
This User Gave Thanks to zaxxon For This Post:
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