python subprocess module gives command not found error if order of command is differerent - linux

I have this code in which i'm using subprocess module to do ssh and run some commands and get the response.
command = "ssh -n " +str(server_name) + " sudo /etc/init.d/postfix status && sudo /etc/init.d/ssh status && sudo /etc/init.d/lldpd status"
result = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
response, err = result.communicate()
print response
it returns
sudo: /etc/init.d/lldpd: command not found
but if i format command like this
sudo /etc/init.d/lldpd status && sudo /etc/init.d/postfix status && sudo /etc/init.d/ssh status
it works perfectly.it won't work if i put lldpd into other than first position in command.
i can run the command on server in any order and it's working.
Edit:-
for this command
sudo /etc/init.d/postfix status && sudo /etc/init.d/ssh status && sudo /etc/init.d/lldpd status
i have this output
sudo: /etc/init.d/lldpd: command not found
postfix is running.
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since Sun 2017-05-28 14:13:49 IST; 19h ago
Process: 20365 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 651 (sshd)
CGroup: /system.slice/ssh.service
└─651 /usr/sbin/sshd -D
May 29 09:36:33 rohit systemd[1]: Reloading OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Received SIGHUP; restarting.
May 29 09:36:33 rohit systemd[1]: Reloaded OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Server listening on 0.0.0.0 port 22.
May 29 09:36:33 rohit sshd[651]: Server listening on :: port 22.
May 29 09:36:33 rohit systemd[1]: Reloading OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Received SIGHUP; restarting.
May 29 09:36:33 rohit systemd[1]: Reloaded OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Server listening on 0.0.0.0 port 22.
May 29 09:36:33 rohit sshd[651]: Server listening on :: port 22.
for this command
sudo /etc/init.d/lldpd status && sudo /etc/init.d/postfix status && sudo /etc/init.d/ssh status
i have this output
lldpd is running.
● postfix.service - LSB: Postfix Mail Transport Agent
Loaded: loaded (/etc/init.d/postfix)
Drop-In: /run/systemd/generator/postfix.service.d
└─50-postfix-$mail-transport-agent.conf
Active: active (running) since Sun 2017-05-28 14:14:10 IST; 19h ago
Process: 20381 ExecReload=/etc/init.d/postfix reload (code=exited, status=0/SUCCESS)
Process: 1350 ExecStart=/etc/init.d/postfix start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/postfix.service
├─ 1474 /usr/lib/postfix/master
├─20395 pickup -l -t unix -u -c
└─20396 qmgr -l -t unix -u
May 29 08:33:43 rohit systemd[1]: Reloaded LSB: Postfix Mail Transport Agent.
May 29 08:33:43 rohit postfix[18121]: Reloading Postfix configuration...done.
May 29 09:36:33 rohit systemd[1]: Reloading LSB: Postfix Mail Transport Agent.
May 29 09:36:33 rohit postfix/master[1474]: reload -- version 2.11.3, configuration /etc/postfix
May 29 09:36:33 rohit postfix[20292]: Reloading Postfix configuration...done.
May 29 09:36:33 rohit systemd[1]: Reloaded LSB: Postfix Mail Transport Agent.
May 29 09:36:33 rohit systemd[1]: Reloading LSB: Postfix Mail Transport Agent.
May 29 09:36:33 rohit postfix/master[1474]: reload -- version 2.11.3, configuration /etc/postfix
May 29 09:36:33 rohit postfix[20381]: Reloading Postfix configuration...done.
May 29 09:36:33 rohit systemd[1]: Reloaded LSB: Postfix Mail Transport Agent.
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since Sun 2017-05-28 14:13:49 IST; 19h ago
Process: 20365 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 651 (sshd)
CGroup: /system.slice/ssh.service
└─651 /usr/sbin/sshd -D
May 29 09:36:33 rohit systemd[1]: Reloading OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Received SIGHUP; restarting.
May 29 09:36:33 rohit systemd[1]: Reloaded OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Server listening on 0.0.0.0 port 22.
May 29 09:36:33 rohit sshd[651]: Server listening on :: port 22.
May 29 09:36:33 rohit systemd[1]: Reloading OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Received SIGHUP; restarting.
May 29 09:36:33 rohit systemd[1]: Reloaded OpenBSD Secure Shell server.
May 29 09:36:33 rohit sshd[651]: Server listening on 0.0.0.0 port 22.
May 29 09:36:33 rohit sshd[651]: Server listening on :: port 22.

Related

sshd service fails to start : ssh.service failed because the control process exited with error code

I'm not sure why it isn't starting or why its preventing me from connecting, i get this error:
root#vmi: "# sudo service ssh status
ssh.service OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Sun 2022-11-27 09:47:47 CST; 4min 58s ago
Docs: man: sshd (8) man: sshd_config(5)
Process: 446 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255/EXCEPTION)
Nov 27 09:47:47 vmi.contaboserver.net systemd[1]: ssh.service: Scheduled restart job, restart>
Nov 27 09:47:47 vmi.contaboserver.net systemd[1]: Stopped OpenBSD Secure Shell server.
Nov 27 09:47:47 vmi.contaboserver.net systemd[1]: ssh.service: Start request repeated too qui>
Nov 27 09:47:47 vmi.contaboserver.net systemd[1]: ssh.service: Failed with result 'exit-code'.
Nov 27 09:47:47 vmi.contaboserver.net systemd[1]: Failed to start OpenBSD Secure Shell server. lines 1-12/12 (END)
Please provide more precise log information, just restart sshd service then use journalctl -xe or vim /var/log/secure (if The storage location of the sshd logs has not been changed)

ssh does not start, bad configuration option

When i try to start the ssh systemctl start ssh i got the following error
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.
The result that i got after the systemctl status ssh.service are
> ● ssh.service - OpenBSD Secure Shell server Loaded: loaded
> (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
> Active: failed (Result: exit-code) since Thu 2020-07-16 12:40:33 EEST;
> 1min 33s ago
> Docs: man:sshd(8)
> man:sshd_config(5) Process: 29636 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=255/EXCEPTION)
>
> Jul 16 12:40:33 raspberrypi systemd[1]: ssh.service: Service
> RestartSec=100ms expired, scheduling restart. Jul 16 12:40:33
> raspberrypi systemd[1]: ssh.service: Scheduled restart job, restart
> counter is at 5. Jul 16 12:40:33 raspberrypi systemd[1]: Stopped
> OpenBSD Secure Shell server. Jul 16 12:40:33 raspberrypi systemd[1]:
> ssh.service: Start request repeated too quickly. Jul 16 12:40:33
> raspberrypi systemd[1]: ssh.service: Failed with result 'exit-code'.
> Jul 16 12:40:33 raspberrypi systemd[1]: Failed to start OpenBSD Secure
> Shell server.
I try the sshd -t command and result are following
/etc/ssh/sshd_config: line 122: Bad configuration option: net.core.netdev_max_backlog
/etc/ssh/sshd_config: terminating, 1 bad configuration options
and the value is net.core.netdev_max_backlog = 3000
I try to unistall - reinstall ssh nothing happent
any ideas what to do please? Thank you
net.core.netdev_max_backlog should not be in /etc/ssh/sshd_config, but in /etc/sysctl.conf

SSH File Transfer from Mint to RPi works not bidirectional

I am new to Linux and RPi. I want to transfer a file from my Pi to my PC.
With ...
scp hello pi#192.168.1.101:/home/pi
.. I am able to transfer my file "hell" to my Pi.
But when I try to send the file "elle" with ...
scp elle mirco#192.168.1.104:/home/mirco
i get
ssh: connect to host 192.168.1.104 port 22: Connection timed out lost connection
I read the ssh service status from the pi and my Computer:
Pi:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2020-04-08 14:38:18 CEST; 6s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 14004 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 14006 (sshd)
Tasks: 1 (limit: 4915)
Memory: 804.0K
CGroup: /system.slice/ssh.service
└─14006 /usr/sbin/sshd -D
Apr 08 14:38:18 raspberrypi systemd[1]: Starting OpenBSD Secure Shell server...
Apr 08 14:38:18 raspberrypi sshd[14006]: Server listening on 0.0.0.0 port 22.
Apr 08 14:38:18 raspberrypi sshd[14006]: Server listening on :: port 22.
Apr 08 14:38:18 raspberrypi systemd[1]: Started OpenBSD Secure Shell server.
My Computer:
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-04-08 14:52:26 CEST; 6min ago
Process: 9224 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Process: 9216 ExecReload=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Process: 8934 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 8935 (sshd)
Tasks: 1 (limit: 4578)
CGroup: /system.slice/ssh.service
└─8935 /usr/sbin/sshd -D
Apr 08 14:52:26 ComputerMirco systemd[1]: Stopping OpenBSD Secure Shell server...
Apr 08 14:52:26 ComputerMirco systemd[1]: Stopped OpenBSD Secure Shell server.
Apr 08 14:52:26 ComputerMirco sshd[8935]: Server listening on 0.0.0.0 port 22.
Apr 08 14:52:26 ComputerMirco systemd[1]: Starting OpenBSD Secure Shell server...
Apr 08 14:52:26 ComputerMirco systemd[1]: Started OpenBSD Secure Shell server.
Apr 08 14:58:12 ComputerMirco systemd[1]: Reloading OpenBSD Secure Shell server.
Apr 08 14:58:12 ComputerMirco sshd[8935]: Received SIGHUP; restarting.
Apr 08 14:58:12 ComputerMirco sshd[8935]: Server listening on 0.0.0.0 port 22.
Can someone help me?
Thank you!
Mirco
Am I correct in thinking you're running the second SCP command on your Pi? If so, your Pi isn't authorized to connect to your PC. You can add it's public key to your authorized_keys file and your Pi will be able to connect to your PC.
You could also pull the file in from your Pi. This is safer because you don't really want your Pi to be able to connect to your PC.
SCP copy to host example
scp pi#192.168.1.101:/home/pi/elle /home/mirco
My guess is that your PC doesn't have ssh enabled.
Install openssh-server on your PC using
sudo apt install openssh-server
After installing this, a system service called ssh should have become active.
You can test this using
sudo systemctl status ssh
Your output should look something like this
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2020-04-08 10:05:07 IST; 13h ago
If it doesn't show active(running), try executing
sudo systemctl enable ssh
If you still are not able to ssh, enable the ssh port through your firewall.
In Ubuntu this can be done by
sudo ufw allow ssh

haproxy error on restarting

HAProxy error on restarting. This is the error i have:
# systemctl status haproxy
● haproxy.service - SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments.
Loaded: loaded (/etc/rc.d/init.d/haproxy; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-11-03 03:34:04 EDT; 16s ago
Docs: man:systemd-sysv-generator(8)
Process: 6170 ExecStart=/etc/rc.d/init.d/haproxy start (code=exited, status=1/FAILURE)
Nov 03 03:34:04 server systemd[1]: Starting SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments....
Nov 03 03:34:04 server haproxy[6170]: /etc/rc.d/init.d/haproxy: line 26: [: =: unary operator expected
Nov 03 03:34:04 server haproxy[6170]: Starting haproxy: [WARNING] 306/033404 (6178) : config : frontend 'GLOBAL' has no 'bind' directive. Please declare it... intended.
Nov 03 03:34:04 server haproxy[6170]: [ALERT] 306/033404 (6178) : Starting frontend http_front: cannot bind socket [0.0.0.0:80]
Nov 03 03:34:04 server haproxy[6170]: [FAILED]
Nov 03 03:34:04 server systemd[1]: haproxy.service: control process exited, code=exited status=1
Nov 03 03:34:04 server systemd[1]: Failed to start SYSV: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments..
Nov 03 03:34:04 server systemd[1]: Unit haproxy.service entered failed state.
Nov 03 03:34:04 server systemd[1]: haproxy.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
My configuration file:
haproxy.cfg
Since you are using systemd, you should use systemd unit file instead of the init.d script.
I don't know how you installed haproxy, you can find haproxy.service in haproxy source directory(contrib/systemd), copy it to systemd folder and use it.
cp contrib/systemd_haproxy.service /lib/systemd/system/
systemctl daemon-reload
systemctl enable haproxy
systemctl start haproxy
systemctl status haproxy

Unable to activate sendmail due to error

I installed sendmail on my Fedora 21 Server installation but when I start it and check it's status I get the following:
[root#localhost mail]# systemctl status sendmail
● sendmail.service - Sendmail Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled)
Active: failed (Result: resources) since Thu 2015-06-04 11:23:31 CEST; 2min 39s ago
Process: 31776 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)
Process: 31766 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)
Process: 31763 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)
Jun 04 11:23:31 localhost.localdomain sendmail[31776]: -bd is not supported by sSMTP
Jun 04 11:23:31 localhost.localdomain systemd[1]: Failed to start Sendmail Mail Transport Agent.
Jun 04 11:23:31 localhost.localdomain systemd[1]: Unit sendmail.service entered failed state.
Jun 04 11:23:31 localhost.localdomain systemd[1]: sendmail.service failed.
What is the problem here? I thought the -bd is not supported by sSMTP was a hint. But I can't find anything on this either.
sSMTP is a send-only sendmail emulator. It does not support -bd option when run as a daemon (see "man ssmtp"). Current sendmail in F21 is an alias to ssmtp. You need to remove ssmtp entirely from F21 (yum erase sSMTP).

Resources