how to set timeout?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to set timeout?
# 8  
Old 02-01-2009
Quote:
Originally Posted by uativan
Thanks a lot.
I changed to use
list=$(ncftpls -u user -p pass -t 2 -x -l ftp://ip/)
echo "$list"

It works great.

Further question is how to split the lines into an array?

Assuming bash or ksh93:

Code:
IFS='
'
list=( $(ncftpls -u user -p pass -t 2 -x -l ftp://ip/) )

# 9  
Old 02-01-2009
Quote:
Originally Posted by cfajohnson
Assuming bash or ksh93:

Code:
IFS='
'
list=( $(ncftpls -u user -p pass -t 2 -x -l ftp://ip/) )

list=$(ncftpls -u user -p pass -t 2 -x -l ftp://ip/)
echo $list output is
drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName1 drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName2 drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName3

IFS='
'
list=( $(ncftpls -u user -p pass -t 2 -x -l ftp://ip/) )
echo $IFS
nothing
echo $list
only drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName1

any problem for me?
# 10  
Old 02-01-2009
Quote:
Originally Posted by uativan
list=$(ncftpls -u user -p pass -t 2 -x -l ftp://ip/)
echo $list output is
drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName1 drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName2 drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName3

Code:
echo "$list"

IFS='
'
list=( $(ncftpls -u user -p pass -t 2 -x -l ftp://ip/) )
echo $IFS
nothing

Not "nothing"; it would print a blank line since $IFS contains a newline.
Quote:

echo $list
only drwxr-xr-x 2 0 0 4096 Dec 19 10:27 FolderName1

It's an array; treat it as such:

Code:
printd "%s\n" "${list[@]}"

# 11  
Old 02-02-2009
Quote:
Originally Posted by cfajohnson
Not "nothing"; it would print a blank line since $IFS contains a newline.
It's an array; treat it as such:

Code:
printd "%s\n" "${list[@]}"

Sorry for so many questions. Thanks first.
I want to add a "/" next to each item in array, is the following method the fastest?

for a in ${list[@]}
do
array=("${array[@]}" $a"/")
done

Last edited by uativan; 02-02-2009 at 12:14 AM..
# 12  
Old 02-02-2009
Quote:
Originally Posted by uativan
Sorry for so many questions. Thanks first.
I want to add a "/" next to each item in array, is the following method the fastest?

for a in ${list[@]}
do
array=("${array[@]}" $a"/")
done

Code:
IFS='
'
array=( printf "%s/\n" "${list[@]}" )

# 13  
Old 02-02-2009
Quote:
Originally Posted by cfajohnson
Code:
IFS='
'
array=( printf "%s/\n" "${list[@]}" )

I used
Code:
 
IFS='
'
list=( $(ncftpls .....) )
array=( printf "%s/\n" "${list[@]}" )

The array become
"printf"
"%s/\n"
"drwxr-xr-x ...."
"drwxr-xr-x ...."
...
# 14  
Old 02-02-2009
Quote:
Originally Posted by uativan
I used
Code:
 
IFS='
'
list=( $(ncftpls .....) )
array=( printf "%s/\n" "${list[@]}" )

The array become
"printf"
"%s/\n"
"drwxr-xr-x ...."
"drwxr-xr-x ...."
...

Sorry. What I meant was:

Code:
array=( $( printf "%s/\n" "${list[@]}" ) )

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Linux

Is it possible to set timeout on Linux screen session

Hello friends, I work on Linux servers via SSH (putty) and run "screen" to preserve my sessions so I can attach/detach them at anytime I wish without losing the connectivity/process disruption which is working perfectly fine. As my team members also have root access to those servers, it is... (7 Replies)
Discussion started by: prvnrk
7 Replies

2. Shell Programming and Scripting

How to set timeout for dev/tcp while checking hostname and port?

I have a command to check the status of hostname and port number, echo > /dev/tcp/hostname/80 echo $? 0 success case echo > /dev/tcp/hostname/809999 I got the output ------------------- connection timed out It took almost 4 minutes to time out,,, how can I set it to 10 seconds? my... (2 Replies)
Discussion started by: sam@sam
2 Replies

3. Red Hat

How to set the screensaver timeout on Red Hat?

How is it possible to set the screensaver timeout on red hat. For solaris I understand it is : for file in /usr/dt/config/*/sys.resources; do dir=`dirname $file | sed s/usr/etc/` mkdir -p $dir echo 'dtsession*saverTimeout: 10' >>$dir/sys.resources echo 'dtsession*lockTimeout: 10'... (0 Replies)
Discussion started by: alvinoo
0 Replies

4. AIX

Set timeout value for ssh session to HMC?

Friends, Could anyone let me know - how to set the timeout value for ssh session to HMC? My HMC version is -- V7R7.4.0. I'm sure the version doesn't have anything to do with it. Thanks, -- Souvik (2 Replies)
Discussion started by: thisissouvik
2 Replies

5. Shell Programming and Scripting

set Net:SSH:Expect timeout and set it again.

SSHing into a machine can take a few seconds, but after I'm in, the commands return quickly. I was wondering if the timeout setting can be changed once I'm logged into the machine. Does anyone know if this can be set on the fly? The problem here is, if I have to set timeout = 10, it'll take 10... (1 Reply)
Discussion started by: mrwatkin
1 Replies

6. UNIX for Dummies Questions & Answers

Is it possible to set a timeout for rpcinfo?

I've created a script that checks the health of a piece of equipment out in the field by first establishing that it is pingable, and then parsing log files to gather information. Today I realized that there are times where the equipment may be pingable, and will not show any immediate issues in... (1 Reply)
Discussion started by: DeCoTwc
1 Replies

7. Shell Programming and Scripting

set timeout for ssh prompt

Hi all, I want to set a timeout say 10 sec to shh prompt i.e. if no password is enetered for 10 sec prompt should again come to shell. How can this be achieved ?? I am using Linux RHEL 5 and Solaris 10. Pls help. Thanks in adv. VIKAS (3 Replies)
Discussion started by: vikas027
3 Replies

8. Programming

How to set the timeout for the client

The scenerio is: 1. A server listens on a port number 2. If the server is down and the Client tries to connect 3. How to set the timeout for the client Detailed explaination: In a client server architecture over a TCP/IP, normally the server is started first which waits and listens for the... (1 Reply)
Discussion started by: shilpi_gup
1 Replies

9. UNIX for Dummies Questions & Answers

how to set timeout for aix?

if a user login and never shutdown or exit...how do you set an automatic shutdown or timeout if the user leave the session on for 20 minutes? thanks (3 Replies)
Discussion started by: ichiro
3 Replies
Login or Register to Ask a Question