LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2008, 06:12 PM   #1
es0teric
Member
 
Registered: Apr 2007
Distribution: Ubuntu
Posts: 105

Rep: Reputation: 19
SSH'ing in shell script


Hey everyone.

I'm trying to use ssh in a shell script to get the disk usage of a certain remote directory.

I've never used ssh in a script before, but here's the syntax I'm currently trying...

ssh $LOGIN_NAME@$HOST "du -sk $DIRECTORY"

I'm trying to test this from the command line before using it in the script, and it hangs as if it's expecting input. It works fine if I just do this though...

ssh $LOGIN_NAME@$HOST du

So I'm assuming the problem is in the spaces and du arguments. I've tried no quotes, double quotes, and single quotes. Nothing worky so far.

Also, I need to snag the output of this command and put it in a local file. Will this work, or am I oversimplifying things?

ssh $LOGIN_NAME@$HOST [du command somehow] >> results_file

Any help would be appreciated. Thanks!
 
Old 07-23-2008, 06:26 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
What does $DIRECTORY expand to?

Your quotes don't do anything here, as the shell strips them before ssh sees them anyway; ssh uses all remaining arguments as the command and the command arguments. Now you might want to quote $DIRECTORY, so that it is seen and passed to ssh as a single argument.

Your shell redirection is fine.
 
Old 07-23-2008, 06:31 PM   #3
es0teric
Member
 
Registered: Apr 2007
Distribution: Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 19
Thanks for the quick reply.

$DIRECTORY expands to a single directory path with no spaces.

/home/h0nk/unrelated/

^ example entry.

So I'm not sure why it chokes if everything at the end is considered part of the command. du with no arguments works fine, but if I append anything beyond that, it just hangs.
 
Old 07-23-2008, 06:43 PM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
Are you using Ubuntu?
 
Old 07-23-2008, 07:20 PM   #5
es0teric
Member
 
Registered: Apr 2007
Distribution: Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 19
Slackware, actually. All machines involved are Slackware machines.
 
Old 07-23-2008, 07:33 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
The command works just fine (I'm using public key authentication).

Have you tried quicker commands such as :

ssh $LOGIN_NAME@$HOST ls -la /tmp
ssh $LOGIN_NAME@$HOST ls -la $DIRECTORY
 
Old 07-24-2008, 12:58 PM   #7
es0teric
Member
 
Registered: Apr 2007
Distribution: Ubuntu
Posts: 105

Original Poster
Rep: Reputation: 19
Yup, sure enough. That was the problem! It was just taking extraordinarily long to execute. I assumed it would take a little while longer, but I just had to let it run longer than I expected I guess.

I'll investigate exactly why it takes longer than (I think) it should, but from a shell script perspective, problem = solved.

Thank you for all your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to ssh from a shell script ? For ppl who can write shell scripts. thefountainhead100 Programming 14 10-22-2008 06:24 AM
ssh'ing an xbox kybishop Linux - Networking 8 01-26-2007 03:08 PM
I made a shortcut to a shell script and it is using default shell icon... shlinux Linux - Software 2 04-20-2006 06:29 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
ssh'ing to hostname hagbardc Linux - Software 4 06-21-2003 10:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration