Global Zone getting crontab info from zone

Hi,

First post.

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.

can anyone help?

davy

When you say that it doesn't work, do you get an error message?

Since you are using 'root' credentials (and not specifying a userid) have you tried using the '-S' safe login switch and, if so, did that fail too?

# zlogin -S $ZONE $COMMAND
1 Like

Thanks for replying.

Yes I have tried the -s option... no difference.

But the code I showed above never gave any error... looked as though it worked... But looking at $MSG there was nothing there...

It is as if the loop just exits on the zlogin

grep /shutdown /zones/*/root/var/spool/cron/crontabs/root

You can access the files in a zone's filesystems directly from the global zone in "/zones/[ZONENAME]/root"

1 Like

zlogin can read from stdin, that is the loop's stdin, in competition with the read comand.
Unless redirected like this

  </dev/null zlogin "$ZONE" crontab -l | grep "/shutdown" >> $MSG
1 Like

I assume that when you say you tried the '-s' switch you actually mean '-S'.

1 Like

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/

1 Like

hicksd8 - yes I did mean that, but i was replying to you from my mobile while I was walking.. sorry.

Jim McNamamara - you let me see this in a different way, so i played around with your suggestion.. we use zonepools for our zones...

so I got it working with this:

#!/bin/sh
#
#
###  Variables
MSG=/tmp/test.txt
HOST=`hostname`
DAT=`date`
ZONES=/tmp/zones.txt

zoneadm list -iv | awk '{ print $4 }' | awk ' length>3 ' | grep -v "PATH" >> $ZONES

while read ZONE
do
    cat $ZONE/root/var/spool/cron/crontabs/root | grep "/shutdown" >> $MSG
done <"$ZONES"

now I just need to format the output for easier reading, etc...

Thanks guys for all of your input, if I did not reply to your suggestion, it does not mean I did not try it....

Thanks will be paid to all.

Davy