Sponsored Content
Top Forums Shell Programming and Scripting Sleep timer based on hostname Post 302692731 by deunan on Tuesday 28th of August 2012 04:55:28 AM
Old 08-28-2012
Sleep timer based on hostname

Dear all

I have a bunch of hosts which I need to run a common script. I need a sleep timee which will delay the execution based on the hostname. Usually the hostname of the servers are host01, host02 .. host16 with which I cam up with this -

Code:
#!/bin/bash
sleeptimer=$(( $(hostname -s|tr -cd 0-9|sed -e 's/^0//') * 60)) 2> /dev/null
#echo $sleeptimer

if [ -z "$sleeptimer" ]
then
	sleeptimer=$RANDOM
	while [ $sleeptimer -gt 3600 ]; do
		sleeptimer=$RANDOM
	done

fi
#sleep $sleeptimer
echo $sleeptimer

The second line works perfectly if the hostname is as previously mentioned with names host01, host02 .. host16.

What if the hostname is simply a generic name without any numbers are the end, I thought of simply generating a number.

Problem is, when the script is executed, I get this error-message
Code:
line 2: * 60: syntax error: operand expected (error token is "* 60")

I've even added "2> /dev/null" at the end of line 2 and it stlll generate the above errors. This only happens on hosts with hostnames *without* tail-numbers

Works fine otherwise ;-)

Appreciate any inputs!

Last edited by deunan; 08-28-2012 at 06:11 AM..
 

7 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Solaris - unknown hostname - how can I change hostname?

Hello, I am new to Solaris. I am using stand alone Solaris 10.0 for test/study purpose and connecting to internet via an ADSL modem which has DHCP server. My Solaris is working on VMWare within winXP. My WinXP and Solaris connects to internet by the same ADSL modem via its DHCP at the same... (1 Reply)
Discussion started by: XNOR
1 Replies

2. UNIX for Dummies Questions & Answers

Timer

is there a timer function in unix without using C? for example i want to display a message after 5 seconds how do i do that? (2 Replies)
Discussion started by: khestoi
2 Replies

3. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

4. Shell Programming and Scripting

Kill a Script based on the pid and sleep

I would want to run a code for 1 min and if it doesnt succeed in 1 min..I would want to exit it..I am using the following code...But the script is not going into my code part.It is waiting for 60 secs and then getting killed. The code which is in the while loop actually takes less than 60 secs...... (6 Replies)
Discussion started by: infernalhell
6 Replies

5. Emergency UNIX and Linux Support

HP UX - ILO Console hostname different than Machine Hostname...

Hi All, So we added a new HP-UX 11.31 machine. Copied OS via Ignite-UX (DVD)over from this machine called machine_a. It was supposed to be named machine_c. And it is when you log in...however when I'm in the ILO console before logging in, it says: It should say: What gives? And how do... (4 Replies)
Discussion started by: zixzix01
4 Replies

6. Shell Programming and Scripting

Program based on hostname

Hi Can you help me get the script for below requirement. when i run below script ./script QM hostname script should be working in below here inputs are QM and hostname by taking inputs it should work like below QM=$1 if QM name ends with 1 $4 should be 51431 ends with ... (4 Replies)
Discussion started by: darling
4 Replies

7. UNIX for Advanced & Expert Users

Hostname -f hostname: Unknown host

deleted (0 Replies)
Discussion started by: hce
0 Replies
check-hostname(1M)					  System Administration Commands					check-hostname(1M)

NAME
check-hostname - check if sendmail can determine the system's fully-qualified host name SYNOPSIS
/usr/sbin/check-hostname DESCRIPTION
The check-hostname script is a migration aid for sendmail(1M). This script tries to determine the local host's fully-qualified host name (FQHN) in a manner similar to sendmail(1M). If check-hostname is able to determine the FQHN of the local host, it reports success. Other- wise, check-hostname reports how to reconfigure the system so that the FQHN can be properly determined. FILES
/etc/hosts Host name database /etc/nsswitch.conf Name service switch configuration file /etc/resolv.conf Configuration file for name server routines ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWsndmu | +-----------------------------+-----------------------------+ |Interface Stability |Evolving | +-----------------------------+-----------------------------+ SEE ALSO
sendmail(1M), hosts(4), attributes(5) SunOS 5.10 10 Nov 2003 check-hostname(1M)
All times are GMT -4. The time now is 09:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy