Passing variable between servers

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Passing variable between servers
# 1  
Old 11-10-2009
CPU & Memory Passing variable between servers

hi everyone,

i need to passing variable from one server to another server.
How can i do it?

Assume that i have got two servers (exp: A and B servers)
i am in A server and i need to get value which in B server.

i think i have to do ftp connection, but after connection how can i get variable?

Thanx so much.
# 2  
Old 11-10-2009

Store variable into file and pass file with SCP.
Then read variable from the file.
# 3  
Old 11-10-2009
Good idea,
sorry what is SCP? Smilie, do you mean FTP with SCP ?

---------- Post updated at 10:13 AM ---------- Previous update was at 09:24 AM ----------

WHAT is SCP? Smilie
# 4  
Old 11-10-2009
temhem, don't worry, when starting everything is "unknown"
but here you can read a little about scp on wikipedia: Secure copy - Wikipedia, the free encyclopedia

basically you would store the variables with values into a file on serverB, and on serverA you would run this command:

# scp user@serverB:/home/user/variable_file.txt ./

where all variables you need would be on server B inside the user's directory in file named variable_file.txt
and that would be copied into the current directory you are on serverA or instead you can use /home/you/ where I have " ./ "

When this command is executed you will be prompt for the "user" password on serverB, enter the password in order for the file to be copied.

If you want to copy this file without being asked for the password every time, you can look into PKI keys, where you have a private and a public key.

Here is how to do it as well:

On server A type:
# ssh-keygen -t rsa

don't enter any phrase just press enter

Then type:
ssh user@serverB mkdir -p .ssh

cat .ssh/ | ssh user@serverB 'cat >> .ssh/authorized_keys'

after that you will be able to get files from the authorized user to your current serverA
Try the command again now:
# scp user@serverB:/home/user/variable_file.txt ./

hope this help, but next time you can do a little research on the forum or google and you will find many resource Smilie

take care

Last edited by pludi; 11-10-2009 at 12:52 PM.. Reason: code tags, please...
# 5  
Old 11-11-2009
THANK SO MUCH sysrenan,

i successed login to server B without password(vi RSA algorithm).
But before running "scp user@serverB:/home/user/variable_file.txt ./"
i have to run script on serverB automatically (without manuel).

i can login to serverB without password. after login i have to run that will creat "odeme" and "taksit" files. After generation files i will copy these files to serverA via mget command.

But after login "" script cant run automatically.

But after login i cant run ""
sftp username@serverB
cd /home/oper
sh ./
mget odeme
mget taksit

Really you are very helpfully,thanx a lot again.

---------- Post updated at 04:16 AM ---------- Previous update was at 03:28 AM ----------

last part was that:

sftp username@serverB<<-EOF
cd /home/oper
sh ./
mget odeme
mget taksit
# 6  
Old 11-11-2009
temhem, you will not be able to run the command "sh" on sftp, from what I know.

if you want to execute commands on serverB and have the output on serverA you can do for example:
ssh user@serverB "ls -ls"

more efficient I think is that you can make all this on serverB, write a script that will do all this and run a CRON Job to send the files from serverB to serverA Smilie

On ServerB:
You can setup CRON JOB by issuing the command:
# crontab -e 
* 12 * * * /home/user/

this will run every 12th hour everyday

name this (as on the cronjob, but you can change it)
don't forget to add executable permission on this file


#run the topl

#send variable files to serverA
scp /home/oper/odeme user@serverA:/home/user/
scp /home/oper/taksit user@serverA:/home/user/

# log the date/time that files were copied
echo "Variable files copied on $(date)" >> /home/oper/variablescopy.log

let me know if that helped
# 7  
Old 11-12-2009
thank you very much sysrenan. Before reading your last response i solved it with Crontab Smilie

you had thought like me. Smilie

Thanx again my friend.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

2. UNIX for Dummies Questions & Answers

Passing value of a variable in sed

Hi, I want to pass value of a variable track_line which is the line number to sed. Sed should print the lines starting from track_line till the last line of the file. I tried the below command but it is not working. sed -n '${track_line},$p' latest_log_file I tried using the below too but... (1 Reply)
Discussion started by: nitinupadhyaya8
1 Replies

3. Shell Programming and Scripting

Passing dynamic variable within another variable.

I have a small program which needs to pass variable dynamically to form the name of a second variable whose value wil be passed on to a third variable. ***************** Program Start ****************** LOC1=/loc1 PAT1IN=/loc2 PAT2IN=/loc3 if ; then for fpattern in `cat... (5 Replies)
Discussion started by: Cyril Jos
5 Replies

4. Shell Programming and Scripting

Passing variable with *

Hi Folks, I would like to pass a variable with a wild card in an argument. My script works if I don't use a wildcard but fails when I use *. I want to use the script like: scriptname -F <filename*> @ i = 0 while ($i <= ${#argv}) switch ($argv) case -F: set j = `echo $i +1... (2 Replies)
Discussion started by: dixits
2 Replies

5. Shell Programming and Scripting

Passing Variable in sed

Dear All, I want to print a file. First I tried with this sed '2q;d' filename it worked. But when i put following it is not working x=2; sed '$xq;d' filename Would any one suggest how to pass the variable? (7 Replies)
Discussion started by: saifurshaon
7 Replies

6. Shell Programming and Scripting

passing a variable inside another variable.

Any help would be great. I know this is a dumb way of doing this, but I would like to know if there is a solution doing it this way. I'm very new at this and I'd like to learn more. Thanks! :D:D count=0 while ; do echo "enter your name" read name_$count let count=count+1 done ... (2 Replies)
Discussion started by: reconflux
2 Replies

7. UNIX for Dummies Questions & Answers

passing a variable inside a variable to a function

I would like to know how to pass a variable inside a variable to a function. sample code below -------------- for x in 1 9 do check_null $C$x ##call function to check if the value is null if then echo "line number:$var_cnt,... (2 Replies)
Discussion started by: KingVikram
2 Replies

8. Shell Programming and Scripting

Passing variable to perl

I need a non-perl (bash) way to strip the path from a list of "find" results. Below is the perl version which I could use, if I could figure out how to call the script with a variable (like in sh, $1 is the variable passed in ./script variable) $file = "/path/to/file.txt"; # How do I... (2 Replies)
Discussion started by: TheCrunge
2 Replies

9. UNIX for Dummies Questions & Answers

Variable passing

Hi, If a script A(Parent) is running and script B(child) is run from script A, will the variables in script A be past to script B? Will the variables exist only for the duration of running the script? Thank you (2 Replies)
Discussion started by: whugo
2 Replies

10. Programming

Passing C Variable To Unix

I want to pass a variable set in my c program to a shell script (which will also be invoked or initiated from the same C program using the C's system command). Is it possible ? :confused: (3 Replies)
Discussion started by: kapilv
3 Replies
Login or Register to Ask a Question