![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I need to write a shell script. | lakshmanrk | Shell Programming and Scripting | 6 | 06-20-2007 06:00 AM |
| please Write a shell script | rvrao77 | Shell Programming and Scripting | 6 | 11-16-2006 10:16 AM |
| need help to write shell script | getdpg | Shell Programming and Scripting | 0 | 04-10-2006 10:30 AM |
| How to write Flat Files by shell script using Oracle Database | coolbuddy | UNIX for Advanced & Expert Users | 3 | 02-21-2006 02:50 PM |
| Help needed to write a shell script! | sreedharsn | Shell Programming and Scripting | 3 | 10-11-2005 12:21 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
shell script to remove old files and write to a log file
Hi,
I have a script that works on a unix box but am trying to get it working on a linux box that uses shell. I am not a programmer so this is proving harder than I imagined. I made some changes and ended up with the script below but when I run it I get the following messages. Any help would be great. messages ./cleanoldbackups.sh: line 18: syntax error near unexpected token `fi' ./cleanoldbackups.sh: line 18: `fi ' script # ----------------------------------------------------------------------- 2>&1 # ----------------------------------------------------------------------- # Check run type - r report, d delete # ----------------------------------------------------------------------- set RUN_TYPE= $1 if [! [$RUN_TYPE == 'r' || $RUN_TYPE == 'd']] then echo "Invalid parameter" $RUN_TYPE exit fi # # ----------------------------------------------------------------------- # Set local variables # ----------------------------------------------------------------------- set LOGFILE= /exlibris/dtl/d3_1/log/cleanoldbackups.log.`date '+%Y%m%d_%H%M%S'` # ----------------------------------------------------------------------- # Switch to backup directory. Find and report/delete files # ----------------------------------------------------------------------- cd /directory/backup #switch $RUN_TYPE case r find . -atime +8 | sort | xargs ls -l >>$LOGFILE breaksw case d find . -atime +8 -exec rm {} \; >>$LOGFILE esac |
|
||||
|
hi,
thanks for the tip. i did make the suggested change and ran the script again but got the following messages; ./cleanoldbackups.sh: line 15: [!: command not found ./cleanoldbackups.sh: line 15: ==: command not found ./cleanoldbackups.sh: line 30: syntax error near unexpected token `find' ./cleanoldbackups.sh: line 30: ` find . -atime +8 | sort | xargs ls -l >>$LOGFILE' Code:
2>&1
# --------------------------------------------------------------------------------
# Check run type - r report, d delete
# --------------------------------------------------------------------------------
set RUN_TYPE= $1
if [! [$RUN_TYPE == 'r' || $RUN_TYPE == 'd']] ; then
echo "Invalid parameter" $RUN_TYPE
exit
fi
#
# --------------------------------------------------------------------------------
# Set local variables
# --------------------------------------------------------------------------------
set LOGFILE= /exlibris/dtl/d3_1/log/cleanoldbackups.log.`date '+%Y%m%d_%H%M%S'`
# --------------------------------------------------------------------------------
# Switch to backup directory. Find and report/delete files not accessed for two weeks.
# --------------------------------------------------------------------------------
cd /san/exlibris1/ueabackup
#switch $RUN_TYPE
case r
find . -atime +8 | sort | xargs ls -l >>$LOGFILE
breaksw
case d
find . -atime +8 -exec rm {} \; >>$LOGFILE
esac
|
|
||||
|
I make the changes to work fine in linux (my test was in slack)
2>&1
# -------------------------------------------------------------------------------- # Check run type - r report, d delete # -------------------------------------------------------------------------------- RUN_TYPE=$1 if [ "$RUN_TYPE" != "r" ] && [ "$RUN_TYPE" != "d" ] ; then echo "Invalid parameter" $RUN_TYPE exit fi -------------------------------------------------------------------------------- # Set local variables # -------------------------------------------------------------------------------- LOGFILE="/home/cassio/remove.log".`date '+%Y%m%d_%H%M%S'` # -------------------------------------------------------------------------------- # Switch to backup directory. Find and report/delete files not accessed for two weeks. # -------------------------------------------------------------------------------- cd /opt/wallis/webserver/logs/ if [ "$RUN_TYPE" == "r" ] ; then find . -atime +8 | sort | xargs ls -l >>$LOGFILE elif [ "$RUN_TYPE" == "d" ] ; then find . -atime +8 -exec rm {} \; >>$LOGFILE fi |
![]() |
| Bookmarks |
| Tags |
| shell script, shell scripting, unix scripting, unix scripting basics |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|