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.

Hello!

Store variable into file and pass file with SCP.
Then read variable from the file.

Good idea,
sorry what is SCP? :), do you mean FTP with SCP ?

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

WHAT is SCP? :frowning:

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

Then:

cat .ssh/id_rsa.pub | 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 :wink:

take care

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 topl.sh script on serverB automatically (without manuel).

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

But after login "topl.sh" script cant run automatically.

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

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 ./topl.sh
mget odeme
mget taksit
bye
EOF

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 :slight_smile:

On ServerB:
You can setup CRON JOB by issuing the command:

# crontab -e 
* 12 * * * /home/user/myscript.sh

this will run every 12th hour everyday

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

#!/bin/bash

#run the topl
/home/oper/topl.sh

#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

thank you very much sysrenan. Before reading your last response i solved it with Crontab :slight_smile:

you had thought like me. :slight_smile:

Thanx again my friend.