如何在Lubuntu 12.04启动时生成一个.sh文件?
在三星N145上网本上运行lubuntu桌面。
到目前为止,我已经/etc/xdg/lxsession/Lubuntu/autostart
添加了该行
@home/magpie/touchpad_settings.sh
我的文件名是touchpad_settings.sh,如果点击则执行并运行,然后执行。
这意味着我不能再登录并获取我的面板,所以我用我的USB启动器解开它并来到这里看看是否有人可以澄清。
Lubuntu不使用启动管理器,这是一个自制文件,因此它也不会在桌面会话设置中。
正如下面的答案所示,我试过了
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. /bin/sh /home/magpie/touchpad_settings.sh exit 0
我也试过这些台词:
/bin/bash /home/magpie/touchpad_settings.sh
和
sh /home/magpie/touchpad_settings.sh
这没用。
在文件管理器中,转到/usr/share/applications
。 使用root访问权限打开它(工具 – >以根目录打开当前文件夹)
在根访问文件管理器窗口中,创建一个新文件(文件 – >新建 – >空文件)
将新文件命名为touchpad.desktop。
找到新创建的文件,右键单击它,使用leafpad编辑它。
在leafpad中,粘贴以下内容:
[Desktop Entry] Name=Touchpad Autostart Exec=/home/magpie/touchpad_settings.sh Type=Application Terminal=false
保存。 如果无法保存,则不在具有root访问权限的窗口中。 重新开始,并仔细按照说明。
再次,在根访问文件管理器窗口中找到您的文件。 右键单击并复制。
现在将根窗口导航到autostart文件夹:
/etc/xdg/autostart/
最后,粘贴您之前创建的桌面文件。
如果你做的一切都正确,你应该会看到很多其他自动启动文件,但你也会看到文件“Touchpad Autostart”
这不是最快速的做事方式,但你似乎在其他答案中遇到了很多步骤,所以我想把它放在很多细节上。 如果您的脚本在重新启动后仍未运行(不要只是注销并重新登录),那么您的脚本就会出现问题。 也许仔细检查?
在具有root权限的编辑器中打开/etc/rc.local
,并在该文件中的行exit 0
之前添加要在启动时执行的命令。
在你的情况下它是
sh home/magpie/myfile.sh
有几种方法可以做到这一点; 最简单的可能是在这个页面和这个指令上按照这些说明创建一个名为autostart的文件夹,进入.config文件夹,然后用文本编辑器创建一个.desktop条目并将其保存在autostart文件夹中。 桌面条目应包含以下行
[Desktop Entry] Name=script.sh Exec=/home/mike/script.sh Type=Application Terminal=false
另一种方法是使用rc.local
文件:
您通常将脚本的完整路径添加到rc.local
文件中; rc.local
仅在其他所有内容启动后执行,并且必须可执行( sudo chmod +x
),如果尚未执行的话。 (Sudo是必要的,因为脚本由root拥有,这就是为什么有些人可能会认为它是root用户启动用户脚本的安全问题,但对于家庭桌面用户来说,使用rc.local
方法是合理的。)
但是,请确保将exit 0
保留为rc.local脚本的最后一行:例如,我的rc.local文件包含脚本的位置和另外两个命令。 如果你想确保你的脚本是由/bin/sh
或/bin/bash
,那就把它放在路径的前面; 例如/bin/bash /home/mike/script
。
最后,使用sudo vi /etc/rc.local
或gksudo gedit /etc/rc.local
编辑文件。
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing # my script here /bin/bash /home/mike/bin/script exit 0
这是我在LXDE环境中添加自动启动程序的最简单方法。
- make’the.sh’执行你想要的程序并将其保存到
/home/user/.config/autostart/the.sh
(记得使它可执行) - 现在将
/home/user/.config/lxsession/LXDE/autostart
文件添加到@sh /home/user/.config/autostart/the.sh
行并重新启动计算机。 而已。
NB! 有些程序需要在启动时延迟,所以例如’conky.sh’必须是
#!/bin/sh sleep 3 conky
– 也许你尝试自动启动’touchpad_settings.sh’的第一种方法只需要延迟.sh文件。
您刚刚在/etc/xdg/lxsession/Lubuntu/autostart
使用了错误的路径:
在线:
@home/magpie/touchpad_settings.sh
@
将被删除,其余的作为shell命令执行。
它使用相对路径:
home/magpie/touchpad_settings.sh
因此,如果当前工作目录是/home/magpie
,它运行的脚本是/home/magpie/home/magpie/touchpad_settings.sh
添加/
来修复它,并确保脚本具有执行权限:
@/home/magpie/touchpad_settings.sh
( @
表示如果退出则会重新启动。)