Upstart 未运行 .sh 脚本

Upstart 未运行 .sh 脚本

upstart网络上关于、init和文件的信息.conf都是垃圾。很多不同的地方展示了完全不同的做事方式。

无论如何,我有一个脚本文件/home/karl/.scripts/startup/sensei-raw-startup.sh(文件权限 775):

#!/bin/bash
# run as root

xinput list >> /var/log/trololol.log

echo trololol start >> /var/log/trololol.log

ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/')

echo trololol before ids >> /var/log/trololol.log
echo $ids >> /var/log/trololol.log
echo trololol after ids >> /var/log/trololol.log

if [ -z "$ids" ]; then
  exit 0;
fi

read -a ids_array <<< $ids

echo fixing id ${ids_array[0]}
xinput set-prop ${ids_array[0]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[0]} 'Device Accel Constant Deceleration' 2.5
xinput set-prop ${ids_array[0]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[0]} 'Device Accel Velocity Scaling' 1

echo fixing id ${ids_array[1]}
xinput set-prop ${ids_array[1]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[1]} 'Device Accel Constant Deceleration' 1.5
xinput set-prop ${ids_array[1]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[1]} 'Device Accel Velocity Scaling' 1

sensei-raw-ctl --show
sensei-raw-ctl --polling 500
sensei-raw-ctl --cpi-on 450
sensei-raw-ctl --cpi-off 5670

unset ids
unset ids_array

echo sensei-raw-startup.sh script `date` >> /var/log/sensei-raw-startup.log

echo trololol end >> /var/log/trololol.log

登录运行脚本时,sudo它运行完美(也会创建日志):

karl@karl-laptop:~/.scripts/startup$ sudo bash sensei-raw-startup.sh 
fixing id 12
fixing id 14
Backlight intensity: low
Backlight pulsation: slow
Speed in CPI (LED is off): 5670
Speed in CPI (LED is on): 450
Polling frequency: 500Hz
karl@karl-laptop:~/.scripts/startup$ 

现在我希望它能够在我登录或计算机启动时自动运行(它应该影响每个登录的用户)。

我创建了该文件/etc/init/karl-startup.conf

description "karls sexy startup script"
author "Karl Morrison"

start on started lightdm

pre-start script
        exec xinput 1> /var/log/karls.log 2>&1
end script

script
        exec bash /home/karl/.scripts/startup/sensei-raw-startup.sh
end script

现在我使用以下命令检查文件:

karl@karl-laptop:~$ init-checkconf /etc/init/karl-startup.conf
File /etc/init/karl-startup.conf: syntax ok

我重新启动了笔记本电脑,登录后发现鼠标设置没有改变,我检查了日志:

karl@karl-laptop:~$ sudo cat /var/log/trololol.log 
[sudo] password for karl: 
trololol start
trololol before ids

trololol after ids

正如你所见,ID 应该显示在哪里12 14它是空白的。

出现以下错误:

karl@karl-laptop:~$ sudo cat /var/log/karls.log
Unable to connect to X server

答案1

文件/etc/init/karl-startup.conf应该读:

description "karls sexy startup script"

正如你所说的你的相关问题你想启动脚本登录时,进一步使用

start on desktop-session-start

如果你想在启动时运行它,请使用

start on startup

exec sudo -u $user /home/karl/.scripts/startup/sensei-raw-startup.sh
exec echo sensei-raw-startup.sh script `date` >> /var/log/karl-startup.log start 

更多详情暴发户这里: http://upstart.ubuntu.com/cookbook/#id300

相关内容