Writing a shell script to untar files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Writing a shell script to untar files
# 1  
Old 08-17-2005
Writing a shell script to untar files

I am new to shell scripting and would appreciate any help I can get.

I need to write a Unix shell script that I will run whenever I have a tar file to uncompress(Korn shell). Please put in mind that I have different environements that I will run it on.


Thanks in advance Smilie
# 2  
Old 08-17-2005
First off, please start new threads in an appropriate forum. You posted this into the "Post Here to Contact Site Administrators and Moderators" I moved it to "Shell programming and scripting Q & A" Thanks.

How do you do it manually? Shell scripting is taking what you do everyday, putting it into a script so you don't have to type as much (typing the same thing every day will normally lead to errors and then more typing).

Code:
#!/bin/ksh
# This script should be run with a parameter (the tar file you want to extract)
if [ "$1" = "" ]
   then echo "Must run script with tar file name"
   else
         tarfile=$1
         tar xf $tarfile
fi
exit

That's just a quick and simple start - note I added checking that the you must put something into parameter 1. This is where scripting becomes to be a bit more than what you do manually. When you are building a script, you have to start realizing that you are doing things you never really think of. You know when there is an error what to do - now you have to code that thinking into the script. How do you know if it was successful? You can code that in. What happens if there is an error or the file name put in as parameter 1 isn't a tar file (or is a tar file but it's compressed). I leave the rest to you to start learning. Come back and ask questions when you get stuck (but always try to find your answers first in man pages, or through a search function on sites like this).

Last edited by RTM; 08-18-2005 at 12:43 AM..
# 3  
Old 08-22-2005
Thank you for your explanation and help
# 4  
Old 08-22-2005
Still having problems/Not getting right results

The purpose of the script is to untar a file that contains directories
The tar file is created on a first box(main server) after a major delivery using FTP and I want to update the second box(failover server).

Part of the script that I have is

# Auxiliar variables
Tarfile=$parm_env`date '+%Y%m%d'`dir.tar

#Change directory to main product area
echo "cd $MAIN_PA"

#Uncompress the tar file
if [ $Tarfile = "" ]
then
$UTILDIR/SLX_Alert.sh $parm_env $thispgm "'Tar file does not exist'" -1
else
tar xf $MAIN_PA/$Tarfile
fi



$parm_env is the environment
$thispgm is the title of the script
$MAIN_PA is th path where the tar file is located

Thank you

Last edited by nkem22; 08-22-2005 at 06:38 PM.. Reason: Needed to explain better
# 5  
Old 08-22-2005
As an aside, you should look into rsync. It's a wonderful, speedy program to keep files and directories in sync.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

2. UNIX for Dummies Questions & Answers

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Discussion started by: ShiGua
4 Replies

3. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

4. UNIX for Dummies Questions & Answers

Writing a loop to process multiple input files by a shell script

I have multiple input files that I want to manipulate using a shell script. The files are called 250.1 through 250.1000 but I only want the script to manipulate 250.300 through 250.1000. Before I was using the following script to manipulate the text files: for i in 250.*; do || awk... (4 Replies)
Discussion started by: evelibertine
4 Replies

5. Shell Programming and Scripting

Shell script required to uncompress and untar files

I need a shell script to Uncompress untar all the files present in the directory (it should Uncompress an untar files present in its sub folders also) In my work I get lots of tar files to untar and update the server, for this each time in need to type Step1) “ Uncompress xyz1-3.tar.z”... (2 Replies)
Discussion started by: arewe
2 Replies

6. Shell Programming and Scripting

Need help in writing the shell script

Can anyone please help me in writing a shell script that would check if a particular user(xyz) has logged in, and if yes, the audit daemon needs to be started. When the user logs off the dameon needs to shutdown , and the report needs to be e-mailed to a set of users. (12 Replies)
Discussion started by: ggayathri
12 Replies

7. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

8. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

9. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies

10. Shell Programming and Scripting

Need help with writing shell script

I have the following output. I want to write a script to check for 1. waits > 0 on all rowsand Ratio > .0. if true then send email. ========================= ROLLBACK SEGMENT CONTENTION ========================= If any ratio is > .01 then more rollback segments are needed NAME ... (1 Reply)
Discussion started by: jigarlakhani
1 Replies
Login or Register to Ask a Question