[SOLVED] bash: sleep not a builtin?

hello,
i have a few scripts running in endless loops, using the sleep command.
this causes constant i/o - not much, but nevertheless.
i went to investigate this further and found that on (archlinux') bash, sleep is not a builtin by default, nor can it be enabled with the "enable" command.
this seems less than optimal to me.
i can't find any packages that would remedy that, either.
how can i solve this?
thoughts, most preferable first:
1) there is some other bash-builtin i've missed, or some workaround that has the same effect.
2) copy the sleep command to /dev/shm/bin and add that to my path. feels hackish, but why not?
3) recompile bash (i read the debian version has sleep as a builtin)?
4) change to another (preferably bash-compatible) shell?
cheers,
o.
Last edited by ondoho (2014-01-06 21:29:31)

dzen for system resource monitoring was something I wanted to bring up, but I wasn't sure what purpose of your script, so I didn't bring it up.
About two or three years ago, I switched to dzen from Conky for system resource monitoring. Like many people, suggestions, and examples on the Internet, I used Bash to write the script [1] to feed the data into dzen. It wasn't long before I realize the script had eaten up 100MB memory.
It was the time I first noticed the issue with Bash scripting. Yes, there are times for cron and should be used with cron, but for this situation and type of case, you can't. I did try to isolate the problem by removing some monitoring components, but, IIRC, the memory was still being eaten.
The 3,000 iterations in my previous might sound a lot at first glance, but the point isn't the iterations but how many invocations of external commands. And 3000 calls of external externally actually ain't a lot, even for one-off or once in long time scripts. That's where the problem is linked from what I see, although I still don't know what the actually cause is.
After I failed to find the leak--or is there really one? I ported the Bash script to C [2]. It's much efficient.
Note that for both code, they are updating as fast as 0.2 seconds depending on what system resources. I found 1 second is too long, especially when you are pressing volume up key, even it's roughly okay for system clock.
I'd advise everyone to take a close look at "TIME+" in top/htop, you might find some programs that you don't expect to use that much time and some the other way around.
By the way, when I said "little obsessive" about myself, I only meant PS1 in loadable C extension is obsessive--who even does like `enable -f vimps1 vimps1` for your PS1? But other parts don't count, because those are clearly wasting if the code is executed a lot and you don't deal with.
[1]: https://github.com/livibetter/dotfiles/ … /status.sh
[2]: https://github.com/livibetter/dotfiles/ … n/status.c

Similar Messages

  • Bash commands not working after upgrade to Lion

    After upgrade, many BASH commands not working. For example, such a fundamental thing as "ls". 
    iMac20:bin a$ ls
    Launch of "ls" failed: the PowerPC architecture is no longer supported.
    What does it have to do with PowerPC? My computer is 2.66 GHz Inter Core Duo

    Linc,
    iMac20:~ a$ which ls
    /sw/bin/ls
    Also, I managed to look (using tcsh's ls-F command) into the contents of /usr/. Here's what I see there:
    [iMac20:/bin] a% ls-F
    [*          csh*        echo*       ksh*        mkdir*      rcp*        stty*       wait4path*
    bash*       date*       ed*         launchctl*  mv*         rm*         sync*       zsh*
    cat*        dd*         expr*       link*       pax*        rmdir*      tcsh*      
    chmod*      df*         hostname*   ln*         ps*         sh*         test*      
    cp*         domainname* kill*       ls*         pwd*        sleep*      unlink*    

  • Bluetooth and sleep not working

    MacBook bluetooth "not available" at the same time as sleep not working (the cd drive wakes up and puts it out of sleep after about 20s). These two faults occur together and are intermittent, though increasing in frequency. I have tried all the fixes (flashing, power reset etc) listed, but none are working, e.g. an earlier post is below. Anyone with any clues - I'm in guarantee but would rather not have people pulling the machine to pieces if I don't need to.
    Thanks
    http://discussions.apple.com/message.jspa?messageID=4571577#4571577

    PS. to the above, just worked out that it only happens when I'm connected to mains power (not on battery) so i guess it's some hardware glitch...

  • I can't send out email using my iPhone4. I tried to follow the step provided to solve but still not working. What should I do?

    I can't send out email using my iPhone4. I tried to follow the step provided to solve but still not working. What should I do?

    Contact your mail provider and get the CORRECT settings for the outgoing server to set up on your phone.

  • [SOLVED] "warning: could not find /bin/bash, starting /bin/sh instead"

    Hello all.
    I've just installed arch, despite very little knowledge of linux (i had ubuntu for a short while before this), but I like a challenge so i thought i'd throw myself in at the deep end.
    The installation went reasonably smoothly, but now i've got it up and running (with a minimal KDE install) but when I open up the konsole, I get the message
    "Warning: Could not find '/bin/bash/', starting '/bin/sh' instead. Please check your profile settings."
    and subsequently I cannot "su jake" (jake being my username, obviously). It requests my password, but when i press return I get the response
    su: /bin/bash/: Not a directory
    which means i've obviously done something wrong, but I cant make head nor tail of the archwiki on Bash, and from googling, I cant find anyone with a similar issue. I can run from root, but it's not ideal.
    Thanks for any response as to why this might be happening, and how to fix it.
    Last edited by hansolo128 (2012-04-24 08:55:37)

    @oxyd
    sh-4.2$ cat /etc/shells
    # /etc/shells
    /bin/sh
    /bin/bash
    # End of file
    root:x:0:0:root:/root:/bin/bash
    jake:x:1000:100::/home/jake:/bin/bash/
    the output of /etc/passwd is
    root:x:0:0:root:/root:/bin/bash
    bin:x:1:1:bin:/bin:/bin/false
    daemon:x:2:2:daemon:/sbin:/bin/false
    mail:x:8:12:mail:/var/spool/mail:/bin/false
    ftp:x:14:11:ftp:/srv/ftp:/bin/false
    http:x:33:33:http:/srv/http:/bin/false
    nobody:x:99:99:nobody:/:/bin/false
    dbus:x:81:81:System message bus:/:/bin/false
    jake:x:1000:100::/home/jake:/bin/bash/
    usbmux:x:140:140:usbmux user:/:/sbin/nologin
    mysql:x:89:89::/var/lib/mysql:/bin/false
    kdm:x:135:135::/var/lib/kdm:/bin/false
    avahi:x:84:84:avahi:/:/bin/false
    moving my home directory from /bin/bash/ to /bin/bash on the line of my username now allows me to su jake, but it doesnt solve the warning that /bin/bash/ doesnt exist.

  • [solved]Gentoo Bash Prompt not working in X

    Hi
    I'm using this .bashrc from AUR:
    http://aur.archlinux.org/packages.php?ID=18418 
    it is said to be the standard bashrc from gentoo.
    It works with xterm, but I now installed urxvt (256 color) and it doesn't work any more, my prompt ist not colored any more.
    I'm not familiar with bash scripting, perhaps someone could have a look.
    The Problem ist not my .Xdefaults, I tried with an empty one. I also did "source .bashrc".
    Last edited by lustikus (2010-01-11 12:24:28)

    thanks for testing it.
    This is my .bashrc. I did not change anything:
    # /etc/bash/bashrc
    # This file is sourced by all *interactive* bash shells on startup,
    # including some apparently interactive shells such as scp and rcp
    # that can't tolerate any output. So make sure this doesn't display
    # anything or bad things will happen !
    # Test for an interactive shell. There is no need to set anything
    # past this point for scp and rcp, and it's important to refrain from
    # outputting anything in those cases.
    if [[ $- != *i* ]] ; then
    # Shell is non-interactive. Be done now!
    return
    fi
    # Bash won't get SIGWINCH if another process is in the foreground.
    # Enable checkwinsize so that bash will check the terminal size when
    # it regains control. #65623
    # http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
    shopt -s checkwinsize
    # Enable history appending instead of overwriting. #139609
    shopt -s histappend
    # Change the window title of X terminals
    case ${TERM} in
    xterm*|rxvt*|Eterm|aterm|kterm|gnome*|interix)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
    screen)
    PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
    esac
    use_color=false
    # Set colorful PS1 only on colorful terminals.
    # dircolors --print-database uses its own built-in database
    # instead of using /etc/DIR_COLORS. Try to use the external file
    # first to take advantage of user additions. Use internal bash
    # globbing instead of external grep binary.
    safe_term=${TERM//[^[:alnum:]]/?} # sanitize TERM
    match_lhs=""
    [[ -f ~/.dir_colors ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
    [[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
    [[ -z ${match_lhs} ]] \
    && type -P dircolors >/dev/null \
    && match_lhs=$(dircolors --print-database)
    [[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true
    if ${use_color} ; then
    # Enable colors for ls, etc. Prefer ~/.dir_colors #64489
    if type -P dircolors >/dev/null ; then
    if [[ -f ~/.dir_colors ]] ; then
    eval $(dircolors -b ~/.dir_colors)
    elif [[ -f /etc/DIR_COLORS ]] ; then
    eval $(dircolors -b /etc/DIR_COLORS)
    fi
    fi
    if [[ ${EUID} == 0 ]] ; then
    PS1='\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
    else
    PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
    fi
    alias ls='ls --color=auto'
    alias grep='grep --colour=auto'
    else
    if [[ ${EUID} == 0 ]] ; then
    # show root@ when we don't have colors
    PS1='\u@\h \W \$ '
    else
    PS1='\u@\h \w \$ '
    fi
    fi
    # Try to keep environment pollution down, EPA loves us.
    unset use_color safe_term match_lhs
    I also made a screenshot with xterm and urxvt in comparison:

  • [SOLVED] Konsole does not close when pressing Crtl+D / defunct bash ?

    Dear all,
    Since a few days, when I type exit or Crtl+D in a KDE konsole to close the bash session, konsole often does not close itself anymore automatically. I tried to close it manually using the GUI (File>Close tab), but then I have the following message:
    The program '/usr/bin/bash' is in this session would not die. Are you sure you want to kill it by force?
    It seems bash is the culprit since ps reveals many [bash] <defunct> lines, probably one for each frozen konsole:
    XXXXXX 2002 0.0 0.0 0 0 ? Zs Nov26 0:00 [bash] <defunct>
    XXXXXX 2220 0.0 0.0 0 0 ? Zs Nov26 0:00 [bash] <defunct>
    XXXXXX 2841 0.0 0.0 0 0 ? Zs Nov26 0:00 [bash] <defunct>
    XXXXXX 2874 0.0 0.0 0 0 ? Zs Nov26 0:00 [bash] <defunct>
    XXXXXX 3525 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 3704 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 3719 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 3827 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 4365 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 4462 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 4475 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    XXXXXX 4559 0.0 0.0 0 0 ? Zs Nov27 0:00 [bash] <defunct>
    Any idea of what could be causing this problem?
    Thanks a lot!
    Aurel.
    Last edited by aurelieng (2013-11-29 08:11:06)

    my .bashrc:
    #!/usr/bin/bash
    export LANG=en_US.UTF-8
    # Source global definitions
    if [ -f /etc/bashrc ]; then
    . /etc/bashrc
    fi
    if [ -f /etc/bash.bashrc ]; then
    . /etc/bash.bashrc
    fi
    # Environment variables
    if [ -f ${HOME}/.environment ];
    then
    source ${HOME}/.environment
    fi
    # Path
    if [ -f ${HOME}/.path ];
    then
    unset TMPPATH;
    for i in `grep -v "^#" ${HOME}/.path `;
    do
    TMPPATH=$TMPPATH:$i;
    done
    export PATH=$TMPPATH:$PATH
    fi
    # Alias
    if [ -f ${HOME}/.alias ];
    then
    source ${HOME}/.alias
    fi
    ulimit -s unlimited
    # Turn off system bell
    setterm -blength 0
    #xset -b
    You can notice i use 3 external files: one containing the paths I want to add to $PATH, one for aliases, and a third one for environment variables. The bash session is initialized as expected, hence I don't think it's worth posting them. Moreover, the fact the bash can't be killed and remains a zombie make me think it might not be related to config files.
    My .bash_profile:
    # .bash_profile
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi
    # User specific environment and startup programs
    PATH=$PATH:$HOME/bin
    export PATH
    unset USERNAME
    # Lines added by tex4moz on: Mon May 12 14:12:58 CEST 2003
    PATH=$PATH:/home/XXXXXXXX/temp/tex4ht.dir ; export PATH
    TEXINPUTS=$TEXINPUTS:/home/XXXXXXXX/temp/tex4ht.dir ; export TEXINPUTS
    Last edited by aurelieng (2013-11-28 06:16:27)

  • [Solved]Bash:Manipulating arrays of paths? the right way or not?

    Note: Refer to the following posts for better solutions and/or alternatives.
    This is a mock segment of a script I'm writting and I need to know if I'm doing it the correct way or at least in a proper bash way...
    the following works but will it always parse in a sorted manner. I have a set of directories that are named by date in the YYYY-MM-DD (International) format and want to be sure that they will always be treated as directory paths even when special characters "\n,\t,\s ...etc" are encountered in the path. The number of these directories changes and is compared to a set NUM-ber variable and when there are more than the set number the oldest ones are removed which brings a second question. Being dated as YYYY-MM-DD they sort from oldest to newest(lexicographical order) but do they always and is this the right way to deal with elements in an array separated by nulls? Any Comments or suggestions would be appreciated as I'm learning bash for the  time being (perl is next) and gathered this from bits and peices on verious wikis and forums. I basically want know if this a correct approach to the subject of extracting and performing actions on elements of an array that are directory paths.
    #!/bin/bash
    oifs="$IFS"
    IFS=$'\0'
    DIRTREE=(/path/to/dated/directories/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    NUM=5
    HOWMANYMORE=$(echo $(( ${#DIRTREE[@]} - $NUM )))
    if (( ${#DIRTREE[@]} > $NUM )) ; then
    rm -rv "${DIRTREE[@]:0:$HOWMANYMORE}"
    fi
    IFS="$oifs"
    Note:I have tested this for those wondering
    Last edited by Thme (2012-11-30 16:58:13)

    aesiris wrote:
    there is a special syntax for appending elements to an array:
    array+=(element1 element2 ...)
    you can simplify to
    NUM=3
    combined=()
    for dir in set1 set2 set3; do
    new=(/home/maat/dateddirs/"$dir"/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    (( count= ${#new[@]} - NUM ))
    combined+=("${new[@]:0:$count}")
    done
    This works as really well, however, in my case I still need the other sets in separate arrays for other purposes in my personal script so I adapted the approach a little and got this which uses the array+=(foo) syntax properly now. I was aware of this feature in bash arrays and experimented with it but had no success adding elements from other arrays until you demonstrated it in your example by adding them though a "for loop" and doing the arithmetic there... My current one now is very similar...I'm not sure how to reduce it further if possible but I need the other arrays as I do something completely different with them:
    #!/bin/bash
    NUM=10
    set1=(/home/maat/datedfolders/set1/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    set2=(/home/maat/datedfolders/set2/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    set3=(/home/maat/datedfolders/set3/[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]/)
    CT1=$(( ${#set1[@]} - NUM ))
    CT2=$(( ${#set2[@]} - NUM ))
    CT3=$(( ${#set3[@]} - NUM ))
    for X in "${set1[@]:0:$CT1}" "${set2[@]:0:$CT2}" "${set3[@]:0:$CT3}"
    do
    combined+=("$X")
    done
    for
    for Xdirs in "${combined[@]}"
    do
    rm -rv "$Xdirs"
    done
    I'm considering changing the title of this thread as it reveals a little more than I originally expected to go over and provides some pitfalls as well as ways to approach array manipulation which can be applied to wide range of uses in bash scripting. Others may find totally different uses for what we've discussed here so....
    Last edited by Thme (2012-11-30 10:41:02)

  • [solved] Bash shell... does not start with user name, but used to...!

    when I start a console, logged in as user, it always used to start with
    user@hostname ~$
    Suddenly, and I cannot recall having done anything that could lead to the issue, konsole will always start as
    bash3.2$                                                     
    even after many reboots, this is still the case.
    whoami shows my user name. I can su to root, and from there to my username, but never directly from bash.
    Occasionally, starting a program like KDE partition manager fails with the error message the program su could not be found. but it is as I said occasional.
    I am quite a newbie to Linux, so I am clueless. Can someone help me..? I tried googling, but I seem to be the only one in the WWW that goofed up to such an extent..! and searches are quite unrevealing.
    I am installing Linux From scratch using arch linux as base system, but I am just following The Book to the letter and don't think that caused the problem.
    Last edited by jaydoc (2009-01-26 09:12:56)

    @weasel8...
    That is THE trouble. And I take back my words, it was during the linux from scratch install that I botched that file...! I was supposed to make a new bashrc file in the LFS directory, but I went wrong on the commands and I think I ended up removing the Arch Linux file...!
    If it is to be found, it should be in the etc directory, right..? I looked there and could not find it. Did I look in the right place...?
    What can I do...?
    Last edited by jaydoc (2009-01-26 07:33:14)

  • [SOLVED] bash: $'\302\240grep': command not found [frequent CLI error]

    For the past several days I've been getting the following error frequently on the command line:
    bash: $'\302\240grep': command not found
    I think I'm only getting this error in response to commands that are piped to grep, such as the following:
    $ ps -ef | grep xyz
    or
    $ locate | grep abc
    However, I don't think I've gotten the error if I type the same commands as above, but without the space between '|' and 'grep'.  And, although the error is frequent, it doesn't happen every time; it is seemingly random.
    Anybody else experiencing this?  Any idea what might be causing it? 
    I'm using rxvt-unicode as my terminal.
    Jay
    Last edited by jt512 (2011-04-06 04:38:56)

    anonymous_user wrote:Post your ~/.bashrc
    # Check for an interactive session
    [ -z "$PS1" ] && return
    function timer () {
    at -f /home/jay/.timercmd now + $1 min
    function cpufs () {
    sudo cpufreq-set -c 0 $1 $2
    sudo cpufreq-set -c 1 $1 $2
    alias ls='ls --color'
    alias kc='~/scripts/kc.py'
    alias diff='colordiff'
    alias s2ram='sudo s2ram -f'
    alias grep='grep --color=always'
    alias Terminal='Terminal -T Terminal'
    alias emacsnw='emacs -nw -f menu-bar-mode'
    alias rm='rm -I'
    alias lpstd='lp -o "StpQuality=Standard"'
    alias paps='paps --paper letter --font="Courier 10"'
    alias mp='mplayer'
    alias mps='mplayer -softvol-max 600'
    alias mysql='$HOME/scripts/mysql'
    if [ $TERM = 'linux' -a $SHELL = '/bin/bash' ] ; then
    PS1='\033[?17;0;40c[\u@\h \W]\$ '
    else PS1='[ \[\e[0;32m\]\u@\h\[\e[m\] \[\e[0;31m\]\W\[\e[m\] \[\e[m\]]\[\e[0;32m\] \$ \[\e[m\]'
    fi
    eval `dircolors -b`
    # Allow tab completion for sudo'ed commands
    complete -cf sudo
    export PATH=$PATH:~/.local/usr/bin
    export EDITOR="vim"
    export BROWSER='conkeror:uzbl-browser:firefox'
    export GREP_COLOR="1;33"
    export LESS_TERMCAP_mb=$'\E[01;31m'
    export LESS_TERMCAP_md=$'\E[01;31m'
    export LESS_TERMCAP_me=$'\E[0m'
    export LESS_TERMCAP_se=$'\E[0m'
    export LESS_TERMCAP_so=$'\E[01;44;33m'
    export LESS_TERMCAP_ue=$'\E[0m'
    export LESS_TERMCAP_us=$'\E[01;32m'
    export SWEAVE_STYLEPATH_DEFAULT="TRUE"

  • [solved]-bash: open: command not found

    Hello, I'm following the tutorial here to set up pure-ftpd https://wiki.archlinux.org/index.php/SFTP
    When I get to the step to create a self signed certificate, this happens
    [root@(none) private]# open ssl req -x509 -nodes -newkey rsa:1024 -keyout \
    > /etc/ssl/private/pure-ftpd.pem \
    > -out /etc/ssl/private/pure-ftpd.pem
    -bash: open: command not found
    Which package do I have to install to get the "open" command?
    Last edited by learnerofskills (2012-01-26 06:39:11)

    skunktrader wrote:take out the space between open and ssl
    That worked. I feel really dumb and embarrassed now. Thank you.

  • [solved]Terminator can not start /bin/bash

    Terminator show an error:
    Unable to start shell:/bin/bash
    this error comes from here:
    /usr/lib/python2.7/site-packages/terminatorlib/terminal.py
    1292 self.pid = self.vte.fork_command(command=shell, argv=args, envv=envv,
    1293 loglastlog=login,
    1294 logwtmp=update_records,
    1295 logutmp=update_records,
    1296 directory=self.cwd)
    1297 self.command = shell
    1298
    1299 self.titlebar.update()
    1300
    1301 if self.pid == -1:
    1302 self.vte.feed(_('Unable to start shell:') + shell)
    1303 return(-1)
    But I can startup terminator using root acount
    the self.pid != -1 when I'm root
    I dont remeber change any privileges ...
    Any idears ?
    Last edited by Hacksign (2013-08-27 01:47:33)

    Scimmia wrote:is /dev/pts listed in /etc/fstab? If so, remove it.
    Thanks, that's actually resolved my problem

  • [Solved] [Bash] How can this NOT work?!?!

    ###### Samsung NC10 Commandcenter ######
    #!/bin/bash
    command=""
    act=""
    args=0
    param=$2
    if [ $# -eq 2 ]; then
        args=2
    fi
    add () {
    if [ args!=2 ]; then
        echo "What do you want to activate?"
        echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
        read act
    fi
    if [ args=2 ]; then
        act=$param
    fi
        case $act in
            1)
            echo "Activating LAN."
            modprobe sky2;
            /etc/rc.d/network start;
            2)
            echo "Activating WLAN."
            modprobe ath5k;
            /etc/rc.d/network start;
            3)
            echo "Activating Bluetooth."
            modprobe btusb;
            modprobe bluetooth;
            echo "Invalid action '$act'!"
        esac
    remove () {
    if [ args!=2 ]; then
        echo "What do you want to inactivate?"
        echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
        read act
    fi
    if [ args=2 ]; then
        act=$param
    fi
        case $act in
            1)
            rmmod sky2;
            /etc/rc.d/network stop;
            2)
            rmmod ath5k;
            /etc/rc.d/network stop;
            3)
            rmmod btusb;
            rmmod bluetooth;
            echo "Invalid action '$act'!"
        esac
    cmd () {
    if [ args!=2 ]; then
        echo "What action do you want to perform?"
        echo -e "1) Suspend(RAM)\t2) Hibernate(HDD)"
        read act
    fi
    if [ args=2 ]; then
        act=$param
    fi
        case $act in
            1)
            echo "Suspending to RAM."
            pm-suspend;
            2)
            echo "Hibernating to HDD."
            pm-hibernate;
            echo "Invalid action '$act'!"
        esac
    if [ $# -ne 0 ]; then
        case $1 in
            add)
            command=1
            rm)
            command=2
            cmd)
            command=3
            command=$1
        esac
    fi
    if [ $# -eq 0 ]; then
        echo -e "Entering interactive mode. \nWhat task would you like to perform? \n1) Activate\t2) Inactivate\t3) Command"
        read command
    fi
    case $command in
        1)
        add
        2)
        remove
        3)
        cmd
        echo "Invalid parameter '$command'!"
    esac
    I'm trying to make a script to control the various functions of my awesome netbook, but even though my design is ingenious , it doesn't work. I've tried everything and I just don't see why it can't work.
    If you start it without arguments, it will ask interactively for the arguments and it works. It works if you pass the first argument, it asks you straight for the second one.
    But it doesn't work if you give both arguments directly. I've tried pretty much everything and I'm about to start punching in walls.
    It's my first real bash script though...
    Last edited by initbox (2009-03-08 16:00:20)

    Now it works!
    All I had to do was add $ in the if-variables and add spaces into the if-conditions.
    Thanks guys.
    Use it if you find it useful, don't care about credits or w/e.
    Finished script:
    #!/bin/bash
    ###### Samsung NC10 Commandcenter ######
    command=""
    act=""
    args=0
    param=$2
    if [ $# -eq 2 ]; then
        args=2
    fi
    add () {
    if [ $args -ne 2 ]; then
        echo "What do you want to activate?"
        echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
        read act
    fi
    if [ $args = 2 ]; then
        act=$param
    fi
        case $act in
            1|lan)
            echo "Activating LAN."
            modprobe sky2;
            /etc/rc.d/network start;
            2|wlan)
            echo "Activating WLAN."
            modprobe ath5k;
            /etc/rc.d/network start;
            3|bt)
            echo "Activating Bluetooth."
            modprobe btusb;
            modprobe bluetooth;
            echo "Invalid action '$act'!"
        esac
    remove () {
    if [ $args -ne 2 ]; then
        echo "What do you want to inactivate?"
        echo -e "1) LAN\t2) WLAN\t3) Bluetooth"
        read act
    fi
    if [ $args = 2 ]; then
        act=$param
    fi
        case $act in
            1|lan)
            /etc/rc.d/network stop;
            rmmod sky2;
            2)
            /etc/rc.d/network stop;
            rmmod ath5k;
            3)
            rmmod btusb;
            rmmod bluetooth;
            echo "Invalid action '$act'!"
        esac
    cmd () {
    if [ $args -ne 2 ]; then
        echo "What action do you want to perform?"
        echo -e "1) Suspend(RAM)\t2) Hibernate(HDD)"
        read act
    fi
    if [ $args = 2 ]; then
        act=$param
    fi
        case $act in
            1)
            echo "Suspending to RAM."
            pm-suspend;
            2)
            echo "Hibernating to HDD."
            pm-hibernate;
            echo "Invalid action '$act'!"
        esac
    if [ $# -ne 0 ]; then
        case $1 in
            add)
            command=1
            rm)
            command=2
            cmd)
            command=3
            command=$1
        esac
    fi
    if [ $# -eq 0 ]; then
        echo -e "Entering interactive mode. \nWhat task would you like to perform? \n1) Activate\t2) Inactivate\t3) Command"
        read command
    fi
    case $command in
        1)
        add
        2)
        remove
        3)
        cmd
        echo "Invalid parameter '$command'!"
    esac
    Last edited by initbox (2009-03-14 12:12:26)

  • [SOLVED] bash: strip: command not found

    In which package is the strip command supposed to be? I must have deleted it unadvertedly...
    Thanks in advance.
    Last edited by iosonofabio (2011-06-15 10:28:23)

    [Archer][~]
    pkgfile strip
    core/binutils

  • Threaded Sudoku solver - Assignment question (NOT LOOKING FOR ANSWERS  )

    Hi All,
    I'm going to be upfront and point out this is an assignment that i'm currently working on and i'm not receiving much in the way of feedback from the class forums.
    This is currently a 4th year OO assignment for UNSW Australia.
    What I am having trouble doing is figuring out where my program is deadlocking or dying. There have been a number of requirements set out by the assignment, basically no synchronization, no locking. We are able to use volatile, atomic, immutable and thread-local objects. The task is to find all solution for a given N x N sudoku problem using X number of threads. I have successfully built the solver (X = 0) without too much trouble and I thought i had managed to modify the recursive algorithm to suit but unfortunately I think I have come unstuck.
    Any generalized tips would be appreciated when implementing threads that utilise checking flags to determine when the thread is finished processing.
    Kind Regards,
    Chris Gibbs

    Honestly, I think that recursion (as you stated) would be the easiest way to have solved this problem. But as you stated, threads must be used to solve this problem as a requirement of the project...
    You could easily launch a Thread each time instead of calling your recursive method... that could possibly result in a crap load of threads, but the idea would work.
    Definitely take a look at the SwingWorker class here if you're able to use J2SE 6: [http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html|http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html]
    I currently use it while gathering data from several websites at the same time. What I did was create and execute() X number of MySwingWorker objects to collect the data, while they are not complete (i.e. MySwingWorker.isDone() is false) I just Thread.sleep(...).
    Give it a try. It may suit your needs.

Maybe you are looking for