When and how is the variable $HOSTNAME populated ?
I am asking because I had a weird situation that just happened.
I have created backup scripts that do backups on different servers. Each servers has different folders to be backed up. So I had included a check on $HOSTNAME to find out which folders to back up.
But tonight, when I started the backup on one server, the backup did not start because it said I was on the wrong server (my coding). I turned out aht the content of the $HOSTNAME was empty. All the other servers had no problems starting the same exact backup script as it $HOSTNAME was containing the right servename.
Here are the steps I did immediatlly after:
A) Checking the content of the $HOSTNAME variable:
- I logged with my own operator userid and did "echo $HOSTNAME". It had the servername in it
- I did a "sudo echo $HOSTNAME" and the content was empty
- I did a "sudo su -" then a "echo $HOSTNAME and the variable had the server name in it.
B) I opened up another window and did the same steps as in A) and all 3 steps showed that $HOSTNAME had a servername content.
I had to resort doing a "sudo su -" and start the backup. Otherwise, I would have had to change the script as a quick workaround.
Somehow, on that specific xterm window I had opened, the content of the $HOSTNAME variable was not populated in all cases. I want to know how this happened and why as it may happen again with another operator (they don't know how to script).
Any variable in the shell comes into existence by your shell's startup scripts...
I would start there. Not sure about ksh, but in bash it would be /etc/bashrc....start there, and that file should lead you to other files that might get "sourced" (processed) within that file. Then there is your local user shell startup file....for instance, "~/.bashrc"
If you know the files, you could "grep -n HOSTNAME" on those files, to show the line numbers where the string HOSTNAME occurs.
funksen and zaxxon are both correct. Never depend on any variables set outside of a script but "bring with you what you need to work with".
The number 1 problem (by a large margin) with cron-scripts is: "i have written a script which ran fine in my shell, then i put it into crontab and now it doesn't work any more. It still runs when i test it." The reason is that your login shell inherits all kinds of environment variables but scripts started by cron don't. If you implicitly rely on - for instance - $PATH being set the same way it is set in your interactive shell you are in for a bad surprise.
Several variables are set in your "~/.profile" and in your "~/.kshrc", but some system-wide variables are set in "/etc/environment". All these files do NOT apply to scripts started by cron.
This is the reason why i have ALL my scripts use their own environment, regardless of them being run in cron or not. The beginning of my scripts always looks like this:
where "/usr/local/lib/ksh/f_env" is a ksh function which declares all the variables common to all the scripts. It looks like this:
I never have to worry about a script being run in cron or not, being run by a specific user or even on a specific system - it won't fail because of the environment being set wrongly.
Hi,
I know how to populate a combo box or a drop down list box which I do as under :
Query that gets the data for the drop down box :
$qry = "select \"EmployeeID\" AS empid, \"FirstName\"::text || ' ' ||\"LastName\"::text as name from \"Employees\"";
$qq =... (1 Reply)
Hi all,
I ended up replacing a failed disk drive on my power 7. I had a few issues with unmirroring as it had a stale logical volume. I ended up finally getting it to unmirror the rootvg. I had an empty space in slot 3 so I ended up putting the new disk in slot 3. It configured to hdisk0 with no... (2 Replies)
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)
from the hostname command I get this:
scosysv.mycompany0
when I ping scosysv.mycompany0 i get 64.158.xx.xx which fails with 100% packet loss.
/etc/hosts shows
199.199.199.1 scosysv scosysv.mycompany0 scosysv.mycompany0.com
when I ping the hostname value isn't the local IP 199.199.199.1... (6 Replies)
Hi,
I am trying to run some SQL scripts under the UNIX server using BTEQ. When I try to create a log file, the file gets populated only to the point where I log into BTEQ.
The log file for the running of the actual script does not seem to be stored.
Would any one know ehy this could be... (3 Replies)
Hi,
I am using hostname environment variable in my shell script to print the host name but it's printing nothing.Can you please help me on this.
Please find the part of the code pasted here:
llist=
llist=$(ps -ef | grep -v grep | grep -c "$1")
echo "Hostname is ${hostname}" (7 Replies)
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)
Using Solaris 8 (or WINXP).
I am trying to look up a specific DNS hostname, but I don't know which DNS server houses that entry. How can I find the hostname?
nslookup gives me the following:
C:\>nslookup hostname
Server: dnsserver
Address: x.x.x.x
*** dnsserver can't find hostname:... (2 Replies)
Hello,
I am installing redhat linux 6.2 on an intel based system. Whether i want to know any naming conventions should i follow.
ie Any convention to follow to name a linux machine(To give hostname). Simillarly for domain name also. Please suggest in this regard (1 Reply)