shell check if file exist in one line with ssh, then cd, and npm install
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have these lines in my script:
ipserver=1.1.1.1
fullpathfile="/var/www/html/mysite"
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] echo "Directory exist" || cd $fullpathfile && npm install "
But I get this error:
Unexpected remote arg: root@1.1.1.1:/var/www/html/mysite/#012ssh root@1.1.1.1 [[
I need to connect through ssh and then check if a folder exist (node_module), if it does not exist, then do: cd folder
and npm install
.
what am I doing wrong ?
shell-script shell
add a comment |Â
up vote
0
down vote
favorite
I have these lines in my script:
ipserver=1.1.1.1
fullpathfile="/var/www/html/mysite"
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] echo "Directory exist" || cd $fullpathfile && npm install "
But I get this error:
Unexpected remote arg: root@1.1.1.1:/var/www/html/mysite/#012ssh root@1.1.1.1 [[
I need to connect through ssh and then check if a folder exist (node_module), if it does not exist, then do: cd folder
and npm install
.
what am I doing wrong ?
shell-script shell
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have these lines in my script:
ipserver=1.1.1.1
fullpathfile="/var/www/html/mysite"
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] echo "Directory exist" || cd $fullpathfile && npm install "
But I get this error:
Unexpected remote arg: root@1.1.1.1:/var/www/html/mysite/#012ssh root@1.1.1.1 [[
I need to connect through ssh and then check if a folder exist (node_module), if it does not exist, then do: cd folder
and npm install
.
what am I doing wrong ?
shell-script shell
I have these lines in my script:
ipserver=1.1.1.1
fullpathfile="/var/www/html/mysite"
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] echo "Directory exist" || cd $fullpathfile && npm install "
But I get this error:
Unexpected remote arg: root@1.1.1.1:/var/www/html/mysite/#012ssh root@1.1.1.1 [[
I need to connect through ssh and then check if a folder exist (node_module), if it does not exist, then do: cd folder
and npm install
.
what am I doing wrong ?
shell-script shell
edited Mar 22 at 18:58
asked Mar 22 at 18:27
stackdave
15116
15116
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15
add a comment |Â
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Note that [[
(and [
and test
) are commands like any other. So you need &&
to only execute the echo
if the [[
succeeds.
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] && echo "Directory exist" || cd $fullpathfile && npm install "
However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@$ipserver" "bash ~/bin/do_npm_install.sh"
1
The~/
should be unnecessary as you will have the home directory as working directory when youssh
to a machine.
â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Note that [[
(and [
and test
) are commands like any other. So you need &&
to only execute the echo
if the [[
succeeds.
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] && echo "Directory exist" || cd $fullpathfile && npm install "
However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@$ipserver" "bash ~/bin/do_npm_install.sh"
1
The~/
should be unnecessary as you will have the home directory as working directory when youssh
to a machine.
â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
add a comment |Â
up vote
0
down vote
accepted
Note that [[
(and [
and test
) are commands like any other. So you need &&
to only execute the echo
if the [[
succeeds.
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] && echo "Directory exist" || cd $fullpathfile && npm install "
However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@$ipserver" "bash ~/bin/do_npm_install.sh"
1
The~/
should be unnecessary as you will have the home directory as working directory when youssh
to a machine.
â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Note that [[
(and [
and test
) are commands like any other. So you need &&
to only execute the echo
if the [[
succeeds.
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] && echo "Directory exist" || cd $fullpathfile && npm install "
However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@$ipserver" "bash ~/bin/do_npm_install.sh"
Note that [[
(and [
and test
) are commands like any other. So you need &&
to only execute the echo
if the [[
succeeds.
ssh "root@$ipserver" "[[ -d $fullpathfile/node_modules ]] && echo "Directory exist" || cd $fullpathfile && npm install "
However, enclosing a series of commands in double quotes like that can get hairy pretty fast, especially if your directory name contains spaces, or your commands need quoted arguments of their own.
To avoid headaches, better to install a little script on the server (for example, as "$HOME/bin/do_npm_install.sh") that does what you need, then invoke that with ssh, like
ssh "root@$ipserver" "bash ~/bin/do_npm_install.sh"
answered Mar 22 at 19:14
Martijn Dekker
1013
1013
1
The~/
should be unnecessary as you will have the home directory as working directory when youssh
to a machine.
â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
add a comment |Â
1
The~/
should be unnecessary as you will have the home directory as working directory when youssh
to a machine.
â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
1
1
The
~/
should be unnecessary as you will have the home directory as working directory when you ssh
to a machine.â Kusalananda
Mar 22 at 19:17
The
~/
should be unnecessary as you will have the home directory as working directory when you ssh
to a machine.â Kusalananda
Mar 22 at 19:17
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
Should being the keyword. It doesn't hurt to write defensive code.
â Martijn Dekker
Mar 22 at 20:10
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432898%2fshell-check-if-file-exist-in-one-line-with-ssh-then-cd-and-npm-install%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Did you by any chance write the script on a Windows machine? Is it a DOS text file?
â Kusalananda
Mar 22 at 19:15