linux - Bash: Read commands from file -



linux - Bash: Read commands from file -

i'm using minimal netinstall image of debian. here script start user processes , daemons @ first login. reads file consisting of commands line line, checks if running , launches them, if not:

#!/bin/bash ## script reads list of user startup daemons , launches them after first login stat=`who | grep "$user" | wc -l` ## login count if [ "$stat" -eq 1 ] ; ## if login shell while ifs=' ' read line ## first effort separate fields fails cmd=`echo "$line" | grep -v ^\#` ## utilize non comment lines if [ -n "$cmd" ] ; eval set "$cmd" ## actual field separation appid=$(pgrep "$1")&& ## check if process $1 of $cmd active , launch if not (echo "$1 active "$appid) || ("$@" 1>/dev/null&& echo "started $1 $(pgrep "$1")") fi done < ~/.scripts/daemons echo "start-daemons: finished" else echo "start-daemons: not login shell" fi

the file of commands ~/.scripts/daemons looks following:

## list of processes / daemons start @ user login ## <command> <argument1> <argument2> .. mpd pulseaudio -d gpg-agent --daemon --enable-ssh-support --write-env-file /tmp/.gpg-agent-info

the script works mpd. problem is, though, lines consisting of command , (multiple) options (and thus, spaces) not splitted fields. setting field separator ifs ' ' makes no difference, find strange. matter in case? give thanks you!

edit: suggested alvits, field separation through evaluating set $line within while loop, provides easy workaround. why read line no separation in first place?

i think should checking "pgrep pulseaudio". is, utilize process/daemon name rather giving process/daemon name along options. don't have machine can test now. can taking first field each line(that process/daemon name). sec one. 1 more thing can seek "-f" alternative of pgrep. seek n allow me know

linux bash sed grep

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -