ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
$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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.