您的位置:

ssh在后台运行php脚本,php ssh

本文目录一览:

黑群晖开启SSH后使用Putty连接,使用admin账户登陆无法获取root权限,如何解决?

此时群晖DSM6正在后台运行脚本执行php程序进行下载,如下图所示

群晖系统默认已经禁止了root账号的了,所以没办法直接用root账号来ssh登录!

登录DSM系统---控制面板---终端机---开启ssh服务,通过putty登录,登录用户名是admin

admin账号登录后

从admin账号切换成root账号,输入下面命令

sudo su -

修改root账号密码为123456

输入下面命令

synouser --setpw root 123456

这样root账号就开启了,密码就是上面修改的123456

默认的群晖DSM系统安装screen较为麻烦,但是有替代命令可以使用,那就是让程序后台运行的命令nuhup

用法

nohup 命令

如何实现SSH断开后 进程仍然在后台运行

解决方法:

1.nohup命令

功能:不挂断地运行命令,忽略HUP信号。

语法:nohup command

实例:

[root@DigMouse ~]# nohup ping 51osos.com /dev/null

[1] 13683

[root@DigMouse ~]# nohup: ignoring input and redirecting stderr to stdout

[root@DigMouse ~]# ls

Desktop Downloads nohup.out

Documents Music Public Videos

[root@DigMouse ~]# cat nohup.out

PING cd447.gotoip.net (122.225.57.246) 56(84) bytes of data.

64 bytes from 122.225.57.246: icmp_seq=1 ttl=56 time=48.6 ms

64 bytes from 122.225.57.246: icmp_seq=2 ttl=56 time=47.8 ms

64 bytes from 122.225.57.246: icmp_seq=3 ttl=56 time=49.9 ms

64 bytes from 122.225.57.246: icmp_seq=4 ttl=56 time=49.5 ms

复制代码

[root@DigMouse ~]# ps -ef | grep ping

root 13683 13655 0 09:33 pts/0 00:00:00 ping 51osos.com

root 13687 13655 0 09:36 pts/0 00:00:00 grep ping

[root@DigMouse ~]#

复制代码

关闭此终端,打开另一个终端使用ps命令,仍然可以查看到ping进程。 无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。

#nohup command command.out 21

上面的例子中nohup command输出的内容输出到了command.out文件中,错误内容输出到了标准输出。

如何在linux服务器后台运行某个进程?在Xshell里需要输入什么指令?

运行命令后面加 是后台运行,但启动它的父进程如果退出,这个 方式运行的依然会退出。

我的建议是用 screen 。这样会启动一个 shell “屏幕”可以随时断开后再另外一个地方重新恢复。

另外还一个方法是用 fg bg nohup 这一套命令也可以。不过具体怎么用我没研究,但控制不如 screen 方便。

其实你这个最好的办法还是写到服务器的开机运行命令行里面,方便很多啊。

另外……占用 ssh 有什么大问题么……

[转载][整理]解决SSH退出登陆后保持进程继续在后台运行

zjking的几个思考写的很好啊忍不住想记下来,侵删

远程ssh用tar打包一个文件夹或者unrar解压一个大文件,即使加了,退出ssh登录时解压进程中断。

ps:直接exit的话会提示 zsh: you have running jobs. ,强行退出会有 zsh: warning: 1 jobs SIGHUPed 提示。

直接转一段wiki

If the process receiving SIGHUP is a Unix shell, then as part of job control it will often intercept the signal and ensure that all stopped processes are continued before sending the signal to child processes (more precisely, process groups, represented internally by the shell as a "job"), which by default terminates them.

This can be circumvented in two ways. Firstly, the Single UNIX Specification describes a shell utility called nohup , which can be used as a wrapper to start a program and make it ignore SIGHUP by default . Secondly, child process groups can be " disowned " by invoking disown with the job id, which removes the process group from the shell's job table (so they will not be sent SIGHUP) , or (optionally) keeps them in the job table but prevents them from receiving SIGHUP on shell termination.

目前有以下几种解决方案:

用途:不挂断地运行命令。

语法:nohup Command [ Arg ... ] [ ]

描述:nohup 命令运行由 Command 参数和任何相关的 Arg 参数指定的命令,忽略所有挂断(SIGHUP)信号。在注销后使用 nohup 命令运行后台中的程序。要运行后台中的 nohup 命令,添加 ( 表示“and”的符号)到命令的尾部。

无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。如果没有文件能创建或打开以用于追加,那么 Command 参数指定的命令不可调用。如果标准错误是一个终端,那么把指定的命令写给标准错误的所有输出作为标准输出重定向到相同的文件描述符。

退出状态:该命令返回下列出口值:

否则,nohup 命令的退出状态是 Command 参数指定命令的退出状态。

nohup命令:如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。nohup就是不挂起的意思( no hang up)。

该命令的一般形式为: nohup command

如果使用nohup命令提交作业,那么在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件:(也就是说自定义输出的文件名)

nohup command myout.file 21

在上面的例子中,输出被重定向到myout.file文件中。

结合重定向知识:

为了不让一些执行信息输出到前台(控制台),我们还会加上刚才提到的/dev/null 21命令来丢弃所有的输出: