Shell scripting newbie - please be gentle.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell scripting newbie - please be gentle.
# 1  
Old 08-01-2007
Data Shell scripting newbie - please be gentle.

Hello Gurus,
Here's my problem, I have log files that are created automatically once a day by a feature of NetBackup called Vault. I usually move these files manually to a different location so I can FTP them later, however I know that this can be automated and so here's the info:

When vault runs it updates a file called session.last in this file there's nothing more than a number (1, 2, 3, 4 etc) and that number can reach double digits. The current number in this file is directly associated to the last directory that's created for the Vault session. Meaning that if the file has the number 5 in it, the newest vault directory will be sid5, and in this directory are the files I need to move.

My question is, in a script using an if statement or any other way for that matter, how do I cat or grep the current number in this file and append it to the newest vault directory, so that my cp command can understand where to look?

Here's what I had managed to device so far and this is really amateur scripting so have a laugh if you must, Smilie

dir=/opt/openv/netbackup/vault/sessions/server_vault/
_2dir=/home/admin/Vault/
fname=/opt/openv/netbackup/vault/sessions/catalina_vault/session.last
#
if [ -f "fname" ]; then
cat $fname | read NUMBER
if [ $NUMBER -lt 100 ] ; then
echo "file exists and will be moved" ;
cp $dir/sid$NUMBER/picklist* > $_2dir/
end
fi
fi

I'm pretty sure the read command isn't doing me any good, this is version 17 of a horrible script to do something simple, any help on this I would really appreciate it.

Thank you all.

Charlie.
# 2  
Old 08-01-2007
Code:
dir=/opt/openv/netbackup/vault/sessions/server_vault
_2dir=/home/admin/Vault
fname=/opt/openv/netbackup/vault/sessions/catalina_vault/session.last
#
if [ -s "$fname" ]
then
   NUMBER=`cat $fname`
   if [ "$NUMBER" -lt 100 ]
   then
      echo "File exists and will be moved."
      mv ${dir}/sid${NUMBER}/picklist* ${_2dir}
   else
      echo "Sequence number is greater than 99, nothing to do."
   fi
else
   echo "File $fname does not exist or is empty!"
fi

# 3  
Old 08-01-2007
Awesome!

Thanks a lot robotronic, that worked like a charm.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Newbie needs help with some bash scripting

Please bear with me, I'm a beginner but have had some experience and decent knowledge to understand things as I read them and I'm in the process of trying to learn more. I recently inherited a UNIX server which has a bash script which is part of a crontab schedule that needs to be modified (or... (3 Replies)
Discussion started by: Danylko
3 Replies

2. Shell Programming and Scripting

Shell Scripting Newbie

Hi Guys, I want to create a shell script to run multiple jobs in sequence. Explaination - If I were to run each jobs individually I would have gone to folder - "abin"(where my shellscript is place) as follows cd abin abin > runappeng.sh abc001 Now, I have list of programs which are like... (8 Replies)
Discussion started by: chaits84
8 Replies

3. Shell Programming and Scripting

Shell scripting newbie problem

I am trying to create a shell script similar to ls, but which only lists directories. I have the first half working (no argument version), but trying to make it accept an argument, I am failing. My logic is sound I think, but I'm missing something on the syntax, I'm guessing in the bolded line? ... (9 Replies)
Discussion started by: Tibor63
9 Replies

4. Shell Programming and Scripting

Newbie Question: What is php shell scripting?

I know php is a Web Development language but what does it have to do with shell scripting. I might be wrong about php. Is there a CLI? How do I make one and how does it work? Please don't answer these if you have any books on this. Please give names of good beginner books for php shell scripting... (3 Replies)
Discussion started by: orszhak
3 Replies

5. Shell Programming and Scripting

Shell Scripting NEWBIE - Need Help

Could someone please recommend a very good shell scripting book for me. I would be starting a new job that would require a very good understanding of shell scripting. Please help. (3 Replies)
Discussion started by: ayoka
3 Replies

6. Shell Programming and Scripting

scripting newbie... some help please?

hi all, i am just getting in to bash scripting, so don't be too harsh... i've created this little backup script, and it's just awfull... ugly, doesn't work like I want it to, the works. anyways, i was hoping some of you might help me improve it and learn a little in the process. what i... (13 Replies)
Discussion started by: jmd9qs
13 Replies

7. Shell Programming and Scripting

scripting newbie needs help

I have written a script that will email a generic user when a device is "offline". I would like to enhance this by having the script lookup a contact's email and automatically add it to the MAIL_LIST. I am trying to lookup and return data based on a field common in two files File 1 ... (0 Replies)
Discussion started by: irishluck66
0 Replies

8. Shell Programming and Scripting

Scripting Newbie

Seems simple but I am having difficulty with this one: I am trying to write a single command line argument (which will be a path) - the program should print out the owner of the path. I can not get anything I write to run. Please help. (5 Replies)
Discussion started by: Kymmers7
5 Replies

9. UNIX for Dummies Questions & Answers

Shell Scripting Newbie

I'm relatively new at this scripting game, just need to learn some basic stuff for data handling. My current need is to write a script that loops through a textfile of filenames, and for each file removes the first line and re-writes that file to a new name. In fact I could do with knowing... (1 Reply)
Discussion started by: mattyjim2
1 Replies

10. UNIX for Dummies Questions & Answers

shell scripting newbie question

Hi all! I'm a newbie to shell scripting. I want to create a script that will store a line from a text file in a variable so I can then use it to open firefox with that text in the address bar (the text file contains a list of addresses). I have tried the following: #!/bin/sh a='sed -n 2p... (2 Replies)
Discussion started by: jazzman
2 Replies
Login or Register to Ask a Question