LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-20-2008, 04:17 AM   #1
wondergirl
LQ Newbie
 
Registered: Feb 2008
Posts: 18

Rep: Reputation: 0
Shell automated patchign script


Hi all!
I'm trying to create an automated script for patching, for my Solaris 8 and 10 systems. The patches have to be applied in single-user mode and the patches are located on an NFS netapp mount (which is basically an NFS mount). All the logs are directed to a central location (the same NFS mount)

When the script below runs, it will create the files and when i reboot the system, it does the patching automatically by the files created, but I saw this message on the console during reboot after patching :

/etc/rcS.d/S9999patches: syntax error at line 8: `patchlist=' unexpected

I'm not sure why this error was shown because when I ran the script below, it didnt have an issue with the array 'patchlist' and created all the proper files.

As a result the patching was done but it seems that the 'if' loop for checking if the patches and properly installed are not not done and hence it does not run the cleanup script etc as expected....

Any help / hint you can give me is greatly appreciated!!

Thanks a lot in advance

========================================


# cat /var/tmp/print_script
#!/bin/bash
#
#
# Automated Patching Script
#
#
#
OS=`uname -a | awk '{print $3}'`;
hostname=`hostname`

rm /etc/rcS.d/S9999patches /var/tmp/cleanup.sh /etc/rcS.d/S9999mounteng /etc/rc3.d/S9999patch_boot

###
### Create a file for cleanup
###

cat >/cleanup.sh <<EOF
#!/bin/sh
rm /etc/rcS.d/S9999patches
rm /mnt/logs
/usr/sbin/reboot
EOF

###
### Create a file for checking status after reboot
###


cat >/etc/rc3.d/S9999patch_boot <<EOF
#!/bin/bash

mkdir /mnt_tmp

/usr/sbin/mount xxxx.xxxx.xxx.xxx:/vol/dev_eng/patching_logs /mnt_tmp
touch /mnt_tmp/${hostname}_RebootSuccess
/usr/sbin/umount /mnt_tmp
rm /cleanup.sh
rm /etc/rc3.d/S9999patch_boot
EOF


if [ "$OS" = "5.8" ]
then

###
### Making the mount for patch location
###

echo "/etc/init.d/inetsvc start" >/etc/rcS.d/S9999mounteng
echo "/etc/init.d/inetinit start" >>/etc/rcS.d/S9999mounteng
echo "/etc/init.d/rpc start" >>/etc/rcS.d/S9999mounteng
echo "mount -a" >>/etc/rcS.d/S9999mounteng
echo "mount -F lofs /export/opt /opt" >>/etc/rcS.d/S9999mounteng
echo "defroute=`egrep -v '^#' /etc/defaultrouter|awk '{print $1}'|head -1`" >>/etc/rcS.d/S9999mounteng
echo "/usr/sbin/route add default ${defroute} " >>/etc/rcS.d/S9999mounteng
echo "/usr/sbin/mount xxxx.xxxx.xxxx.xxxx:/vol/dev_eng /mnt" >>/etc/rcS.d/S9999mounteng
echo "/usr/sbin/mount xxxx.xxxx.xxxx.xxxx:/vol/dev_eng/patching_logs /mntlogs" >>/etc/rcS.d/S9999mounteng


###
### Create file for actual patching
###

cat >/etc/rcS.d/S9999patches <<EOF
#!/bin/bash

hostname=`hostname`

cd /mnt/patch_location1;./patch_install
cd /mnt/patch_location2;./patch_install

patchlist=( 109862-05 112438-03 109326-20 )
element=0
element_count=${#patchlist[@]}

patch_success=`while [ "$element" -lt "$element_count" ]
do
patch="/var/sadm/patch/${patchlist[$element]}"
if [ ! -f $patch ]
then
echo -n "Failure"
exit 0
fi
let "element = $element +1"
done`

if [ "$patch_success" != "Failure" ]
then
touch /mntlogs/${hostname}_PatchSuccess
else
touch /mntlogs/${hostname}_PatchFailure
fi

/usr/sbin/umount /mnt
/usr/sbin/umount /mntlogs

/bin/sh /cleanup.sh /dev/null 2>&1
EOF


else


###
### Making the mount for patch location
###

mkdir /mntlogs
echo "/usr/sbin/mount xxxx.xxxx.xxxx.xxxx:/vol/dev_eng /mnt" >>/etc/rcS.d/S9999mounteng
echo "/usr/sbin/mount xxxx.xxxx.xxxx.xxxx:/vol/dev_eng/patching_logs /mntlogs" >>/etc/rcS.d/S9999mounteng


###
### Create file for actual vtm patching
###

cat >/etc/rcS.d/S9999patches <<EOF
#!/bin/bash

cd /mnt/patch_location1;./patch_install

patchlist=( 119059-32 )
element=0
element_count=${#patchlist[@]}

vtm_success=`while [ "$element" -lt "$element_count" ]
do
patch="/var/sadm/patch/${patchlist[$element]}"
if [ ! -f $patch ]
then
echo -n "Failure"
exit 0
fi
let "element = $element +1"
done`

if [ "$patch_success" != "Failure" ]
then
touch /mntlogs/${hostname}_PatchSuccess
else
touch /mntlogs/${hostname}_PatchFailure
fi

/usr/sbin/umount /mnt
/usr/sbin/umount /mntlogs
/bin/sh /cleanup.sh /dev/null 2>&1
EOF

fi


chmod 500 /etc/rcS.d/S9999patches
chmod 500 /cleanup.sh
chmod 500 /etc/rcS.d/S9999mounteng
chmod 500 /etc/rc3.d/S9999patch_boot

Last edited by wondergirl; 02-20-2008 at 04:18 AM.
 
Old 02-20-2008, 05:13 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
In a line like
cat >S99999 <<EOF
put EOF in quotes, like:
cat >S99999 <<"EOF"

Otherwise you have to escape and $, \ and ` characters.

Take a look at the S9999patches script.

What happens is that in a line such as,
element_count=${#patchlist[@]}
the ${#patchlist[@]} expression is evaluated before being written to the script.

The code between the backticks disappears altogether.

Last edited by jschiwal; 02-20-2008 at 05:20 AM.
 
Old 02-20-2008, 05:02 PM   #3
wondergirl
LQ Newbie
 
Registered: Feb 2008
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jschiwal View Post
Take a look at the S9999patches script.

What happens is that in a line such as,
element_count=${#patchlist[@]}
the ${#patchlist[@]} expression is evaluated before being written to the script.

The code between the backticks disappears altogether.
Thanks for your comments!! I really appreciate it. But unfortunately, I dont understand the relation between the ${#patchlist[@]} expression being evaluated to the code between the backticks disappearing. Sorry for my thick head, but can you explain more with perhaps an example?

Thanks again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automated FTP shell script RedOctober45 Linux - Software 1 01-09-2008 08:58 AM
Automated Backup Script mukundmurari Linux - Newbie 2 10-23-2007 07:18 AM
[HELP] Script for automated compiling hbinded Programming 10 08-22-2006 03:30 AM
Install script for Automated RH mac_casey Linux - General 3 11-11-2002 02:41 PM
Automated su script? elmetald00d Linux - General 5 04-08-2002 11:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration