I want to script my ESX 3.0.1 server installs, and utilize a shell script in the post section of the ks.cfg file to do some additional automated configuration. My question is how do you call this shell script? Does is get stored on an http or ftp server? I'm unclear on where you tell the ks.cfg file and ESX server to find the script.
sorry, just realised, that you answered to sbeaver...
what (i think) he wants you to do is to put all your commands in /etc/rc.local . That is a file that is called after the complete init (cat /etc/rc.local).
And don't forget to save and restore the orginal rc.local although, there seems to be only one command inside.
anyway...
just try it as i described. the link /etc/rc3.d/S99MyStartup is automatically called during each startup (as all links in /etc/rc3.d/ -> try a "ls" in there) and due pointing to the script /etc/init.d/MyStartup this script is called.
you may want to look at this:
http://www.linux.com/article.pl?sid=04/06/23/1734235
Message was edited by:
kri-2
You have to decide if you are going to get the files from a network share or FTP ect. What you can do is backup rc.local and then call your script from there. When it reboots for the last time after post it will run the script called from rc.local just make sure you restore the backup of that file when you are done or each time the servers boots it will try to run the script
Hi,
the shellscript can be created during the post section
So just append the %post section in your ksfile as follows:
%post
touch /etc/init.d/MyStartup #create the scriptfile
chmod 710 /etc/init.d/MyStartup #make it executtable
ln -s ../init.d/MyStartup /etc/rc3.d/S99MyStartup #create a late (99) link in rc3
cat > /etc/init.d/MyStartup <<EOF
#!/bin/sh
#script your commands here! e.g:
touch /tmp/PostScriptSuccessfullyRan
rm /etc/rc3.d/S99MyStartup
mv /etc/init.d/MyStartup /tmp
/sbin/reboot
#done
EOF
This will do the following:
-runs the main install routine
-creates the MyStartup file, fills it with the commands and creates a link in rc3
-reboots as ever
-runs the commands from MyStartup and reboots again, done!
-and dont forget to delete or move the link and startup script as in my example! (a running script deleting it self after work works fine)
-be careful with variables ($foo) and backticks "``", they have to be escaped with "\" to not beeing executed during the cat proccess
e.g: echo \$foo or if \[ -n \`ls\` ]
Hope this helps!
I'm a bit of a novice here, so how do i call the script from rc.local?
sorry, just realised, that you answered to sbeaver...
what (i think) he wants you to do is to put all your commands in /etc/rc.local . That is a file that is called after the complete init (cat /etc/rc.local).
And don't forget to save and restore the orginal rc.local although, there seems to be only one command inside.
anyway...
just try it as i described. the link /etc/rc3.d/S99MyStartup is automatically called during each startup (as all links in /etc/rc3.d/ -> try a "ls" in there) and due pointing to the script /etc/init.d/MyStartup this script is called.
you may want to look at this:
http://www.linux.com/article.pl?sid=04/06/23/1734235
Message was edited by:
kri-2
kri-2 has a way posted that will work well but to answer your question create a backup of rc.local
mv -f /etc/rc.d/rc.local /etc/rc.d/rc.local.sav
Here is an example of my post
\# Post install
%post
(
echo "(fd0) /dev/fd0"
echo "(hd0) /dev/cciss/c0d0"
) >> /boot/grub/device.map
cp /boot/grub/grub.conf /tmp/grub.conf
cat /tmp/grub.conf | sed -e "s/root (hd.*)/root (hd0,0)/g" > /boot/grub/grub.conf
/sbin/grub-install /dev/cciss/c0d0
\# Download the altiris agent binaries during post
\# FTP server evaluates to RDP server's IP address during token replacement
ftpip=%#*"select tcp_addr from aclient_prop where computer_id=0"%
\# Transfer Altiris Linux agent, adlagent
mkdir /tmp/altiris
cd /tmp/altiris
ftp -n <<EOF2
open $ftpip
user anonymous rdp
cd /dslib/osoem/altiris
binary
prompt
\# Download x86 adlagent
mget altiris*.i386.bin
\# Download custom adlagent config if it exists
mget adlagent.conf.custom
mget adlagent.conf.default
exit
EOF2
AltirisConfDir=/opt/altiris/deployment/adlagent/conf
\# create script to configure ESX and install adlagent (called by rc.local)
cat > /tmp/altiris/hpinstall.sh << EOF1
#!/bin/bash
\# Script to configure ESX and install adlagent. Called from rc.local.
\# Firewall Configuration
\# Enable adlagent and file transfer ports
\# You need to set a static port ("4300" in this example) for file transfer in
\# the deployment console under Tools->Options->Global
esxcfg-firewall --openPort 402,tcp,out,adlagent
esxcfg-firewall --openPort 5001,tcp,out,adlagentFileTransfer
\# Install Altiris Adlagent
cd /tmp/altiris
chmod +x altiris-adlagent*.bin
./altiris-adlagent*.i386.bin 1>>/root/install.rdp.log 2>>/root/install.rdp.log
\# Install adlagent custom configuration
if \[ -e adlagent.conf.custom ]; then
mv $AltirisConfDir/adlagent.conf $AltirisConfDir/adlagnet.conf.bak
cp -f adlagent.conf.custom $AltirisConfDir/adlagent.conf
elif \[ -e adlagent.conf.default ]; then
mv $AltirisConfDir/adlagent.conf $AltirisConfDir/adlagent.conf.bak
sed -e "s/0.0.0.0/%#*"select tcp_addr from aclient_prop where computer_id=0"%/g" adlagent.conf.default > $AltirisConfDir/adlagent.conf
fi
\# Reset adlagent to pick up config if necessary
/etc/init.d/adlagent stop
/etc/init.d/adlagent start
\# Reset rc.local to original
mv -f /etc/rc.d/rc.local.sav /etc/rc.d/rc.local
EOF1
\# End of script
\# make hpinstall.sh executable
chmod +x /tmp/altiris/hpinstall.sh
\# save a copy of rc.local
cp /etc/rc.d/rc.local /etc/rc.d/rc.local.sav
\# add hpinstall.sh to rc.local
cat >> /etc/rc.d/rc.local << EOF
cd /tmp/altiris
/tmp/altiris/hpinstall.sh
EOF
This will create a script and launch that script from rc.local. Hope this helps
Good examples. I think i can handle it from here. Thank you
I know this is an older post, but when I did it as you described, it does not run the file. Is there anything that may be missing here. I used the exact same script.
touch /etc/init.d/VMCfg
chmod -x /etc/init.d/VMCfg
ln -s /etc/init.d/VMCfg /etc/rc3.d/S99VMCfg
cat > /etc/init.d/VMCfg <<EOF
When the server reboots it does not run this linked file.
chmod -x removes the execute bit, you need to add it with +x
