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 :wink:

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).

#!/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).

Thank you for your explanation and help

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

As an aside, you should look into rsync. It's a wonderful, speedy program to keep files and directories in sync.