Friday, March 12, 2010

FTP

#! /bin/ksh
#--------------------------------------------------
# kill the file in case nothing is found
#--------------------------------------------------
rm /ux012/lynn/vax.filelist
#--------------------------------------------------
# start ftp from vax 
#   i : turns off interactive prompting
#   n : turns off manual login
#--------------------------------------------------
ftp -in lark <<EOF
quote user ltobias
quote pass lct1234
ls ms123:[xyz]*.txt /ux012/lynn/vax.filelist
quit
EOF
#--------------------------------------------------
# after closing the ftp, display what's in the file
#--------------------------------------------------
more /ux012/lynn/vax.filelist

Thursday, March 11, 2010

Does a File Exist?

for EXTENSION in txt TXT csv CSV xls XLS            # For each one in this list,
do                                                  # do the following:
  echo $EXTENSION                                   # Display the extension.
  if [ -e *.$EXTENSION ];                           # if a file exists like that...
     then ls *.$EXTENSION |wc -l                    # then display the count
          mv *.$EXTENSION /dfact/fchecks/out_backup # move file to the backup dir
     else echo '    -- not found'                   # otherwise, display 'not found'   
  fi
done

Moving files with Script

#! /bin/sh
echo "# +-----------------------------------------------------------------------"
echo "# | Script ID:     backup_output.sh"
echo "# | Purpose:       This script moves the daily output files to a backup "
echo "# |                directory and cleans out the previous day's files"
echo "# +-----------------------------------------------------------------------"
echo " "
echo "# +-----------------------------------------------------------------------"
echo "# | clean out backup directory before proceeding to copy                  "
echo "# +-----------------------------------------------------------------------"

cd /xyz/out_backup                                            # Change to output backup
echo "Directory: "; pwd                                       # Display on screen

for EXTENSION in txt TXT csv CSV xls XLS doc DOC              # For each one in this list,
do                                                            # do the following:
  echo $EXTENSION                                             # Display the extension.
  if [ -e *.$EXTENSION ];                                     # if a file exists like that...
     then ls *.$EXTENSION |wc -l                              # then display the count
          rm *.$EXTENSION                                     # delete those files
     else echo '    -- not found'                             # otherwise, display 'not found'  
  fi                                                         
done                                                         

echo "Directory: "; pwd                                       # Display on screen
echo "Anything left?"
ls

echo "# +-----------------------------------------------------------------------"  
echo "# | copy files only if they exists                                        "
echo "# +-----------------------------------------------------------------------"  

cd /xyz/output                                                # Change to output directory
echo "Directory: "; pwd                                       # Display on screen

for EXTENSION in txt TXT csv CSV xls XLS doc DOC              # For each one in this list,
do                                                            # do the following:
  echo $EXTENSION                                             # Display the extension.
  if [ -e *.$EXTENSION ];                                     # if a file exists like that...
     then ls *.$EXTENSION |wc -l                              # then display the count
          mv *.$EXTENSION /xyz/out_backup                     # move those files to the backup dir
     else echo '    -- not found'                             # otherwise, display 'not found'  
  fi                                                         
done                                                         

echo "Directory: "; pwd                                       # Display on screen
echo "Anything left?"
ls