- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script help - test command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 04:05 AM
тАО02-25-2005 04:05 AM
Here is the script:
echo "Verifying /var/adm/cron/cron.allow..."
if [ $(test -f /var/adm/cron/cron.allow) ]; then
if [ $(grep -q root /var/adm/cron/cron.allow) ]; then
echo "\troot is in cron.allow"
else
echo "root\n" >> /var/adm/cron/cron.allow
fi
if [ $(grep -q oracle /var/adm/cron/cron.allow) ]; then
echo "\toracle is in cron.allow"
else
echo "oracle\n" >> /var/adm/cron/cron.allow
fi
else
echo "root\noracle\n" >> /var/adm/cron/cron.allow
fi
chmod 644 /var/adm/cron/cron.allow
chown root:system /var/adm/cron/cron.allow
echo "COMPLETED - Verifying /var/adm/cron/cron.allow.\n"
Even if the cron.allow is there and has root and oracle in it, it is still adding them. I know it isn't "catching" on the first "if" statement so something must be wrong with my "test" command.
Thanks again..
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 04:09 AM
тАО02-25-2005 04:09 AM
Solutionif [ $(test -f /var/adm/cron/cron.allow) ]; then
to
if [[ -f /var/adm/cron/cron.allow ]];then
your code.
Also grep statements as follows.
stat=$?
root=$(grep -i root /var/adm/cron/cron.allow > /dev/null 2>&1)
if [[ ${stat} -ne "0" ]];then
echo "root\n" >> /var/adm/cron/cron.allow
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 04:12 AM
тАО02-25-2005 04:12 AM
Re: Script help - test command
change your test command from :
if [ $(test -f /var/adm/cron/cron.allow) ]; then
to
if [[ -f /var/adm/cron/cron.allow ]]; then
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 04:14 AM
тАО02-25-2005 04:14 AM
Re: Script help - test command
to change your syntax:
#!/usr/bin/sh
FNAME="/var/adm/cron/cron.allow"
if [[ -f ${FNAME} ]]
then
grep -q "root" S{FNAME}
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "root found"
else
echo "root not found"
fi
fi
Note the use of the [['s and ]]'s in lieu of the more traditional ['s and ]'s. The double brackets utilize the shell's internal tests rather than relying upon the external test command. Under this syntax logical and's are && (rather than -a) and logical or's are || (rather than -o). grep -q returns a zero result when a match is found and non-zero otherwise.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 07:20 AM
тАО02-25-2005 07:20 AM
Re: Script help - test command
Here's a VERY simple way to check for cron.allow and add root and oracle:
#!/usr/bin/ksh
FILE="/var/adm/cron/cron.allow"
MODF="$FILE.$$.mod"
if [[ -f "$FILE" ]]; then
egrep -v "^root|^oracle" $FILE >$MODF
echo "root" >> $MODF
echo "oracle" >> $MODF
cp -p $MODF $FILE
else
echo root > $FILE
echo oracle >> $FILE
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 07:32 AM
тАО02-25-2005 07:32 AM
Re: Script help - test command
The script I provided is short and simple and I'm sure it will work for you. Also, I hit submit before I remembered the rest of your message. You are setting permissions of your cron.allow file a little loose. If you are security consciencious, you should set permissions to 700.
Also, the owner and group should be root, bin, or sys (you show root:system ... I think you want root:sys unless you renamed the sys group to system or created a system group.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 07:35 AM
тАО02-25-2005 07:35 AM
Re: Script help - test command
Do you have a cron.deny file? If there is a cron.deny file and the cron.deny file has the default accounts in it, the cron.allow file does not have to exist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-25-2005 07:37 AM
тАО02-25-2005 07:37 AM
Re: Script help - test command
[ -f /var/cron/cron.allow ] && echo "\troot is in cron.allow" || echo "root\n" >> /var/adm/cron/cron.allow
The [[ ... ]] construct is for more specialized conditions including testing undefined variables. The && and || are shortcuts for if-then-else-fi. In your original construct, the $(test...) code is redundant because test and [...] are the same thing. See: man test
Bill Hassell, sysadmin