[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Cannot rum multiple command on remote machine via SSH



Am 04/02/2023 um 12:26 schrieb Kamil Jońca:
Ottavio Caruso <ottavio2006-usenet2012@yahoo.com> writes:

Hi,

LAP1 is a Thinkpad that I use only at home as a poor man's desktop.

LAP2 is a second Thinkpad that I use mainly outdoors, on which I run
an SSH server to do some syncing every now and again.

Both using latest Debian stable with similar sets of apps.

At night, I want to connect to LAP2 and perform these commands:

$ sudo tlp setcharge 90 95 BAT1 # resets battery settings for external
battery

$ hibernate.sh # a script that performs some housekeeping, puts laptop
into hibernation and eventually disconnects sshd.

 From LAP1 I can issue:

$ ssh LAP2 sudo tlp setcharge 90 95 BAT1 # it works

or:

$ ssh LAP2 hibernate.sh # it works too

but either:

$ ssh LAP2 "sudo tlp setcharge 90 95 BAT1 && hibernate.sh"

or

$ ssh LAP2 "sudo tlp setcharge 90 95 BAT1 ; hibernate.sh"

return:

hibernate.sh: command not found

your shell interpret this as two commands

1. run "sudo tlp setcharge 90 95 BAT1"
2. then run "hibernate.sh" (without sudo)

you can try
--8<---------------cut here---------------start------------->8---
ssh LAP2 "sudo tlp setcharge 90 95 BAT1 ; sudo hibernate.sh"
--8<---------------cut here---------------end--------------->8---
or
--8<---------------cut here---------------start------------->8---
ssh LAP2 "sudo sh -c 'tlp setcharge 90 95 BAT1 ; hibernate.sh'"
--8<---------------cut here---------------end--------------->8---

No, this is not good. The "hibernate.sh" must be run as standard user.


--
Ottavio Caruso

A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?



Reply to: