LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-07-2012, 02:11 AM   #1
Shark82
Member
 
Registered: Sep 2010
Posts: 90

Rep: Reputation: 3
ZSH - PATH problem when using script via udev rule


So, i have migrated to zsh and averything is fine except a little PATH problem. Now, i hava a power saving script that is executed when i unplug the power line (via udev rule). Till migration to zsh averything worked fine but when i changed #!/bin/bash to #!/bin/zsh in script, it doesn't work anymore. I found out that script is workable only if i write full paths in it, eg. /sbin/hdparm... instead of hdparm... When i am in terminal or console PATH variable is working fine. I also found out, for now, that the problem are commands in /sbin and /usr/sbin folder - commands in /usr/bin are working just fine.


My PATH:
Code:
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/vendor_perl:/usr/bin/core_perl
My /etc/profile
Code:
# /etc/profile

#Set our umask
umask 022

# Set our default path

PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin"
export PATH

# Load profiles from /etc/profile.d
if test -d /etc/profile.d/; then
        for profile in /etc/profile.d/*.sh; do
                test -r "$profile" && . "$profile"
        done
        unset profile
fi

# Source global bash config
if test "$PS1" && test "$BASH" && test -r /etc/bash.bashrc; then
        . /etc/bash.bashrc
fi

# Termcap is outdated, old, and crusty, kill it.
unset TERMCAP

# Man is much better than us at figuring this out
unset MANPATH
My script:
Code:
#!/bin/zsh

case "$1" in
  true) # Enable power saving settings on battery
        # Device Runtime-PM
        #for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo auto > $dpcontrol; done
        # Disable nmi_watchdog
        echo 0 > /proc/sys/kernel/nmi_watchdog
        # kernel write mode
        echo 5 > /proc/sys/vm/laptop_mode
        echo 1500 > /proc/sys/vm/dirty_writeback_centisecs
        # disk powersave
        hdparm -S 36 -B 128 /dev/sda &> /dev/null
        for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo min_power > $i; done
        # sound card powersave
        echo 60 > /sys/module/snd_hda_intel/parameters/power_save
        echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
        # wlan0 powersave
        iwconfig wlan0 power on
        # backlight
        echo 2 > /sys/class/backlight/acpi_video0/brightness
        ;;
  false) # Return to default on AC power
        # Device Runtime-PM
        #for dpcontrol in /sys/bus/{pci,spi,i2c}/devices/*/power/control; do echo on > $dpcontrol; done
        # Enable nmi_watchdog
        echo 1 > /proc/sys/kernel/nmi_watchdog
        # kernel write mode
        echo 0 > /proc/sys/vm/laptop_mode
        echo 500 > /proc/sys/vm/dirty_writeback_centisecs
        # disk powersave
        hdparm -S 0 -B 254 /dev/sda &> /dev/null
        for i in /sys/class/scsi_host/host*/link_power_management_policy; do echo max_performance > $i; done
        # sound card powersave
        echo 300 > /sys/module/snd_hda_intel/parameters/power_save
        echo Y > /sys/module/snd_hda_intel/parameters/power_save_controller
        # wlan0 powersave
        iwconfig wlan0 power off
        #backlight
        echo 13 > /sys/class/backlight/acpi_video0/brightness
        ;;
esac
exit 0
 
Old 11-07-2012, 07:59 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
If you intend to keep using zsh, you should spend some time reading The ZSH User's Guide and creating your own .zsh and .zshenv files in your home directory. That alone may solve most of your problems when running scripts written for bash.

Zsh uses the $PATH variable, but is also uses a $path array, which is more flexible than using the PATH env variable.

The Zsh Guide discussion of PATH begins on page 47.

Excerpt:
Quote:
It helps to be able to find external programmes, i.e. anything not part of the shell, any
command other than a builtin, function or alias. The $path array is used for this. Actually,
what the system needs is the environment variable $PATH, which contains a list of directories
in which to search for programmes, separated from each other by a colon. These directories
are the individual components of the array $path. So if $path contains
path=(/bin /usr/bin /usr/local/bin .)
then $PATH will automatically contain the effect of
PATH=/bin:/usr/bin:/usr/local/bin:.
without you having to set that. The idea is simply that, while the system needs $PATH
because it doesn’t understand arrays, it’s much more flexible to be able to use arrays within
the shell and hence pretty much forget about the $PATH form.
 
Old 11-08-2012, 02:51 AM   #3
Shark82
Member
 
Registered: Sep 2010
Posts: 90

Original Poster
Rep: Reputation: 3
Hi

I have solved the problem by creating file /etc/zsh/zshenv and write this down:

Code:
path=(/usr/local/bin /usr/bin /bin /usr/local/sbin /usr/sbin /sbin)
Thanks!

Last edited by Shark82; 11-08-2012 at 02:57 AM.
 
Old 11-08-2012, 06:13 AM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
It would be better if you created file ~/.zshenv and put your corrections there. By having the corrections in /etc/zsh/zshenv, you risk losing the corrections every time zsh is updated.
 
Old 11-08-2012, 07:14 AM   #5
Shark82
Member
 
Registered: Sep 2010
Posts: 90

Original Poster
Rep: Reputation: 3
You are right but there is one problem. I have a script that is executed by udev and this script is in /etc folder. If i move /etc/zsh/zshenc to ~/.zshenv the udev won't respect this paths in .zshenv.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem with udev rule on fedora 15 blue_bob Linux - Hardware 5 05-10-2012 07:55 PM
Problem Using Udev Rule akash2happy Programming 3 01-23-2012 01:44 AM
udev rule to invoke a script vinaytp Linux - Newbie 2 03-29-2011 06:35 AM
First UDEV Rule, Not quite there ... orbit Slackware 7 02-22-2009 10:08 PM
udev rule problem with 12.2 conundrum07 Slackware 8 01-04-2009 12:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration