I have a script that I am having a little trouble with and I hope someone can help.
I will post the code for your input, but I want to read the lines of a file and use this as input to a command in a while loop...
#!/bin/sh
#
#
### Variables
MSG=/tmp/tmptest.txt
HOST=`hostname`
DAT=`date`
ZONES=/tmp/tmpzones.txt
#this next line works fine
zoneadm list | grep -v "global" | sort >> $ZONES
# the next line performed here works perfectly well - if I type the server name in manually (hashed out just now)
# zlogin SERVER_NAME crontab -l | grep "/shutdown" >> $MSG
while read ZONE
do
# the next line is what i want to achieve, but does not work - tried different combinations of " ' ` in different places...
#echo zlogin "$ZONE" crontab -l | grep "/shutdown" >> $MSG
# the next line proves the while loop works
echo "this works for $ZONE" >> $MSG
done <"$ZONES"
Say my ZONES file produces
Server1
Server2
Server3
then my while loop just now produces:
"this works for Server1"
"this works for Server2" ... etc
but I am wanting to do a zlogin to the server(s) within the global zone to get the crontab info of that server if it has a reboot set.. then i can email it out to the relevant users.
First off, the root user if it is enabled as a user and not a role can see the directories of all the non-global zone, from the global zone. From the global zone the directory zones can have many names:
cd /path/to/zones # probably /etc/zones but some installations use different naming.
cd Zone_I_Want/root/path_to_root_crontab # ./root is the / directory in the non-global zone.
You can now treat the crontab file as if it was completely local, which it really is now.
From the Zone_I_Want/root directory the entire non-global zone and all mounted filesystems can be read/written. BE CAREFUL. Just read.
This will work only when the zone is up and running with all of its filesystems mounted. Unmounted zones only show a few directories off root/