hello, im a newbie in unix scripting. can someone pls send me a sample script that will tar files in the folders of a specific directory, but will exclude specific files, and afterwards, will ftp the tar into another server.
for example:
in this directory, /export/home/acrandru/testing/
the following files and folders will be tar'd (this are not all the files/folders in this directory)
copyright.html
license.txt
license.html
classes --this folder also has files inside--
src --this is a folder
but will exclude these files in these directories:
export/home/acrandru/testing/copyright.html
export/home/acrandru/testing/license.txt
I have tried to create a script located in /export/home/acrandru/ays/tar_files.sh
this is a sample of the file
#!/bin/ksh
# Uncomment "set -x" below for script debugging
set -x
# Set Environment Variables ----- BEGIN
# The set -a option exports all variables
# until the set +a command is executed
set -a
. /opt/psoft/.profile 1
LOGS_DIR=/export/home/acrandru
SCRIPTS_DIR=/export/home/acrandru
OUT_DIR=/export/home/acrandru/
SCRIPT_NAME=tar_files.sh
SCRIPT_LOG=$SCRIPT_NAME.log
set +a
# Set Environment Variables ----- END
# Show env. variable int text file for debugging
set > $LOGS_DIR/$SCRIPT_LOG
cd $OUT_DIR
echo $OUT_DIR >> $LOGS_DIR/$SCRIPT_LOG
path=`pwd`;
echo $path >> $LOGS_DIR/$SCRIPT_LOG
CUR_MON=`date|awk '{print $2}'`;
CUR_YR=`date +%Y`;
echo "CURRENT MONTH: " $CUR_MON >> $LOGS_DIR/$SCRIPT_LOG
echo "CURRENT YEAR: " $CUR_YR >> $LOGS_DIR/$SCRIPT_LOG
if [ $path = $OUT_DIR] ;then
(
echo "Tar monitoring directory" >> $LOGS_DIR/$SCRIPT_LOG
$ tar cf /export/home/acrandru/tar.tar --exclude-from=/export/home/acrandru/ays/exlude_files.txt *
echo "Creating tar file for aonprod08" >> $LOGS_DIR/$SCRIPT_LOG
ExitCode=0
if [ $ExitCode -ne 0 ]
then
echo "Cannot create tar file" >> $LOGS_DIR/$SCRIPT_LOG
fi
)
fi
exit 0
_____
when i try to run the script, i get an error:
CUR_MON=Dec
+ + date +%Y
CUR_YR=2003
+ echo CURRENT MONTH: Dec
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ echo CURRENT YEAR: 2003
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ echo Tar monitoring directory
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ $ tar -cf /export/home/acrandru/tar.tar --exclude-from=/export/home/acrandru/ays/exclude_files.txt exclude_files.txt tar_files.sh tar_files.sh.log tar_files2.sh tar_files3.sh tar_files3.sh.log
./tar_files3.sh[55]: $: not found
If anyone out there can help me out, i'd really appreciate it.
You can email me at ajrandrup@yahoo.com, or if you would like to discuss with me, my aim id is aysrandrup, or at yahoo, ajrandrup
for example:
in this directory, /export/home/acrandru/testing/
the following files and folders will be tar'd (this are not all the files/folders in this directory)
copyright.html
license.txt
license.html
classes --this folder also has files inside--
src --this is a folder
but will exclude these files in these directories:
export/home/acrandru/testing/copyright.html
export/home/acrandru/testing/license.txt
I have tried to create a script located in /export/home/acrandru/ays/tar_files.sh
this is a sample of the file
#!/bin/ksh
# Uncomment "set -x" below for script debugging
set -x
# Set Environment Variables ----- BEGIN
# The set -a option exports all variables
# until the set +a command is executed
set -a
. /opt/psoft/.profile 1
LOGS_DIR=/export/home/acrandru
SCRIPTS_DIR=/export/home/acrandru
OUT_DIR=/export/home/acrandru/
SCRIPT_NAME=tar_files.sh
SCRIPT_LOG=$SCRIPT_NAME.log
set +a
# Set Environment Variables ----- END
# Show env. variable int text file for debugging
set > $LOGS_DIR/$SCRIPT_LOG
cd $OUT_DIR
echo $OUT_DIR >> $LOGS_DIR/$SCRIPT_LOG
path=`pwd`;
echo $path >> $LOGS_DIR/$SCRIPT_LOG
CUR_MON=`date|awk '{print $2}'`;
CUR_YR=`date +%Y`;
echo "CURRENT MONTH: " $CUR_MON >> $LOGS_DIR/$SCRIPT_LOG
echo "CURRENT YEAR: " $CUR_YR >> $LOGS_DIR/$SCRIPT_LOG
if [ $path = $OUT_DIR] ;then
(
echo "Tar monitoring directory" >> $LOGS_DIR/$SCRIPT_LOG
$ tar cf /export/home/acrandru/tar.tar --exclude-from=/export/home/acrandru/ays/exlude_files.txt *
echo "Creating tar file for aonprod08" >> $LOGS_DIR/$SCRIPT_LOG
ExitCode=0
if [ $ExitCode -ne 0 ]
then
echo "Cannot create tar file" >> $LOGS_DIR/$SCRIPT_LOG
fi
)
fi
exit 0
_____
when i try to run the script, i get an error:
CUR_MON=Dec
+ + date +%Y
CUR_YR=2003
+ echo CURRENT MONTH: Dec
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ echo CURRENT YEAR: 2003
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ echo Tar monitoring directory
+ 1>> /export/home/acrandru/ays//tar_files3.sh.log
+ $ tar -cf /export/home/acrandru/tar.tar --exclude-from=/export/home/acrandru/ays/exclude_files.txt exclude_files.txt tar_files.sh tar_files.sh.log tar_files2.sh tar_files3.sh tar_files3.sh.log
./tar_files3.sh[55]: $: not found
If anyone out there can help me out, i'd really appreciate it.
You can email me at ajrandrup@yahoo.com, or if you would like to discuss with me, my aim id is aysrandrup, or at yahoo, ajrandrup