Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to get servername?

Status
Not open for further replies.

p62483t

Programmer
Jan 14, 2008
11
US
Does any one knows how I can get the servername that my script is runnin on?
 
put a uname -a command within the script?

I want to be good, is that not enough?
 
Or simply uname -n for the server name only.

I want to be good, is that not enough?
 
I am very new at this can u give me an example? I want to get the name and put it as part of a path
 
Sorry I was at lunch. Glad you sorted it!

I want to be good, is that not enough?
 
Can you tell me how can i asign the returned value to a variable?
something like this but i don't know the exact sintax

servername = "uname -n" maybe?
servername = "$(uname -n)" maybe?

then i want to display the servername
echo "servername" = servername maybe like this ?

sorry i don't know the sintax jet...
 
try:

export SERVERNAME=`uname -n`

echo $SERVERNAME
Note tha the ` in the above are back-ticks (usually found above the tab key), not regular apostrophes.

I want to be good, is that not enough?
 
i have a question about shell script and SCP, i found some example on the net how to write such scripts, but they are all assume that there is no password, anybody have any idea how to write a shell script to upload a file to a server that will ask for password. using SCP.??
 
Try this on the machine you want to copy FROM. Type the command...
Code:
ssh-keygen -t rsa
Just hit return for all of the prompts. Don't enter a passphrase.

Then type the following command, where "[tt]myuser[/tt]" is your username on the machine you want to copy TO, and "[tt]desthost[/tt]" is the machine you want to copy TO.
Code:
cat ~/.ssh/id_rsa.pub | ssh myuser@desthost "cat - >> ~/.ssh/authorized_keys"
You will be prompted for a password when you do this command.

You should then be able to copy a file like this in a script without needing a password...
Code:
scp file.ext myuser@desthost:file.ext
 
Oops! Developer1001, you should start your own thread if you have a question, not piggyback on someone elses thread on a different topic. I didn't read carefully and thought you were the original poster asking more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top