The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Writing shell script bmkreddy Shell Programming and Scripting 2 04-15-2007 12:04 PM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-11-2006 11:27 PM
Need help for writing shell script deepa20 Shell Programming and Scripting 3 02-01-2006 10:23 AM
Need Help Writing Shell Script***please KristenT Shell Programming and Scripting 7 01-31-2006 03:00 PM
Writing a shell Script Chin UNIX for Dummies Questions & Answers 1 06-03-2005 01:32 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-17-2005
Registered User
 

Join Date: Aug 2005
Posts: 4
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
Reply With Quote
Forum Sponsor
  #2  
Old 08-17-2005
RTM's Avatar
RTM RTM is offline
Hog Hunter
 
Join Date: Apr 2002
Location: On my motorcycle
Posts: 3,039
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-17-2005 at 08:43 PM.
Reply With Quote
  #3  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 4
Thank you for your explanation and help
Reply With Quote
  #4  
Old 08-22-2005
Registered User
 

Join Date: Aug 2005
Posts: 4
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 02:38 PM. Reason: Needed to explain better
Reply With Quote
  #5  
Old 08-22-2005
Registered User
 

Join Date: Oct 2002
Posts: 676
As an aside, you should look into rsync. It's a wonderful, speedy program to keep files and directories in sync.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0