passing ip address as a variable to script for ftp


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers passing ip address as a variable to script for ftp
# 1  
Old 08-31-2005
passing ip address as a variable to script for ftp

Still a Beginner here ..

Does anyone no how to get the IP address of the machine thats logged in (bearing in mind there will be others logged in) while they are logged in to the Unix server and pass this as a variable to a shell script so as I can FTP files to that machine via a shell script, at present I have only developed the ftp/shell script to a specific (named) machine

I would like "HOST" to equal the persons ipaddress that is logged in if possible

sample of present code

#! /usr/bin/ksh

HOST=gerry
USER=gerry
PASSWD=letmein
DIR=/uploads
exec 4>&1
ftp -nv >&4 2>&4 |&
print -p open $HOST
print -p user $USER $PASSWD
print -p cd c:\
print -p dir c:\uploads
print -p binary
print -p get $DIR/CHEST /u1/excel/Kenny/CHEST
print -p bye
wait
exit 0
bye

Last edited by Gerry405; 08-31-2005 at 12:50 PM..
# 2  
Old 08-31-2005
you can use "who -q <user>" to get the IP-address (i tried that on AIX 5.2) and put that info into your variable.

Sample output of "who -q":
f985905 (130.20.158.93)

Therefore:

HOST="$( who -q | sed 's/.*(\([^)]\).*/\1/' )"

bakunin
# 3  
Old 09-01-2005
thanks for that but under Data General -Unix that command does not work but, the only command that'll produce an IP address that i'm aware of is finger and last


# finger
Login Name TTY Idle When Where
esco Elizabeth Scoular pts/0 2:47 Thu 07:40 j-ward
jwil janet wilson!general pts/1 2:41 Thu 07:47 160.120.10.232
bkir B Kirkbride! Stores pts/2 2:40 Thu 07:48 j-mccormick

# last |pg

jwar pts/6 e-scoular Thu Sep 1 09:20 - 10:03 (00:42)
jrob pts/4 172.17.24.64 Thu Sep 1 08:30 still logged in
jwar pts/3 e-scoular Thu Sep 1 07:58 still logged in
bkir pts/2 j-mccormick Thu Sep 1 07:48 still logged in
jwil pts/1 160.120.10.232 Thu Sep 1 07:47 still logged in

# tty
/dev/pts/5

Last edited by Gerry405; 09-01-2005 at 07:16 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable from called script to the caller script

Hi all, Warm regards! I am in a difficult situation here. I have been trying to create a shell script which calls another shell script inside. Here is a simplified version of the same. Calling Script. #!/bin/ksh # want to run as a different process... (6 Replies)
Discussion started by: LoneRanger
6 Replies

2. Shell Programming and Scripting

Passing value of variable to a query within shell script

I have a script in which i connect to database to run a query and get the result of the query to a temp file. This works fine , now what i want is there is flat file which contains the value to be used in the query. I want to read this file line by line and then run the query for each value in that... (7 Replies)
Discussion started by: gpk_newbie
7 Replies

3. Shell Programming and Scripting

Passing variable as an argument to another script

Hi, I am trying to pass a variable as an argument to another script. While substitution of variable, I am facing a problem. varaiable "a" value should be -b "FPT MAIN". When we pass "a" to another script, we are expecing it to get substitue as ./test.sh -b "FPT MAIN". But, it is getting... (9 Replies)
Discussion started by: Manasa Pradeep
9 Replies

4. Shell Programming and Scripting

help passing variable from script

Hello, How can I pass a variable into a 2nd file? I'm running a script: ls -la $1 >pem99 cat pem99 | awk '{ print $3}' >us99 cat us99 | read us98 This then tells me the owner of a file. my second file is: echo OWNER GROUP OTHERS echo echo --data-- $us98 ... (2 Replies)
Discussion started by: Grueben
2 Replies

5. Shell Programming and Scripting

Passing variable from shell script to python script

I have a shell script main.sh which inturn call the python script ofdm.py, I want to pass two variables from shell script to python script for its execution. How do i achieve this ????? Eg: main.sh a=3 b=3; c= a+b exec python ofdm.py ofdm.py d=c+a Thanks in Anticipation (4 Replies)
Discussion started by: shashi792
4 Replies

6. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

7. Shell Programming and Scripting

passing asterisk to a script as variable

I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's... (9 Replies)
Discussion started by: GKnight
9 Replies

8. UNIX for Dummies Questions & Answers

passing variable to my script

Hello everybody: Im trying to run the following script on my sol9 machine: line='' ((lineCount= 0)) export lineCount more /tmp/MSISDNs | wc -l > /tmp/tmp cat /tmp/tmp | read lineCount export lineCount; while (( lineCount > 0 )) do line= tail -$lineCount... (5 Replies)
Discussion started by: aladdin
5 Replies

9. UNIX for Advanced & Expert Users

Passing a variable into an awk script

Hello all, I'm trying to run a script of this format - for i in $(cat <file>); do grep $i <file1>|awk '{print $i, $1, $2}' It's not working - does anyone know how this can be done? Khoom (5 Replies)
Discussion started by: Khoomfire
5 Replies

10. Shell Programming and Scripting

Random parameters passing in FTP script

Hi I have a question. In the FTP script if we are passing all the required value like Hostname, username, password, Action(put or get), Filename, & mode(ascii or binary) through parameters then we have to pass these in the exact orders in which they are taken like if we defined Username=$2... (2 Replies)
Discussion started by: sourabhshakya
2 Replies
Login or Register to Ask a Question