4

Here is my 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.
/bin/echo 12 > /sys/class/backlight/acpi_video0/brightness
/bin/echo disable > /proc/acpi/ibm/bluetooth

# Samsung at home
/usr/bin/xrandr --newmode "1680x1050_60.00"  146.25  1680 1784 1960 2240 1050 1053 1059 1089 -hsync +vsync
/usr/bin/xrandr --addmode VGA1 1680x1050_60.00
/usr/bin/xrandr --output VGA1 --mode 1680x1050_60.00

exit 0

whose permission is -rwxr-xr-x.

The first command works, I can set the brightness of my laptop's monitor. The following script is to disable bluetooth and to set resolution of my external monitor.

Only the first command is correctly executed, not the others.

I know that rc.local stops running when a command fails. However, I've tried to run it manually

/bin/sh /etc/rc.local

Everything seems to work correctly, the bluetooth is disabled and the resolution is set without problem. I've also tried to run the first command in terminal

/bin/echo 12 > /sys/class/backlight/acpi_video0/brightness
echo $?

It shows that the first command returns zero.

So I don't understand why the system doesn't run all the commands in rc.local. I really need it, especially for the first 2 lines which need root permission.

  • 2
    Try putting set -x in the script to have debugging info printed to the screen. Or pipe each commands standard error and standard out to tee – spuder Feb 9 '14 at 18:56
  • 2
    Add exec >/var/tmp/rc.local.1.out 2>/var/tmp/rc.local.2.out at the beginning of the file and check those files for error messages. – Mark Plotnick Feb 9 '14 at 23:15
4

/etc/rc.local is executed before the X server starts, so it has no access to any GUI features. The xrandr commands cannot have any effect.

Put the xrandr commands in a different file, which runs when your GUI session starts. The file depends on your desktop environment.

  • Thanks @Gilles, I've put the xrandr commands in an other file and added it to the autostart list of my xfce environment. Now the resolution setting works. – user6417 Feb 10 '14 at 3:42
1

Problem solved,

As @Gilles said, I should put xrandr commands in an other file since rc.local is executed before X. So I've put all xrandr commands in a other script file, and added it to the auto-start list of my xfce environment, now resolution setting works.

However for Bluetooth, apparently it's a timing issue, I've found that the Bluetooth is disabled for a few milliseconds, then turn on again. It looks like something has reactivate the Bluetooth after running rc.local.

So I've added sleep 5 at the beginning of rc.local, now problem solved.

0

Rather than loosing 5 seconds to sleep why not put the Bluetooth disable to your xrandr script that runs with auto-start?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.