fish shell: Prompt changing to '>' - fish

I recently switched to fish and modified one of the prompts available from fish_config to look like this.
function fish_greeting
fortune
end
function fish_prompt
echo
set -l retc brblack
test $status = 0; and set retc bryellow
set -q __fish_git_prompt_showupstream
or set -g __fish_git_prompt_showupstream auto
function _nim_prompt_wrapper
set retc $argv[1]
set cust $argv[4]
set field_name $argv[2]
set field_value $argv[3]
set_color normal
set_color $retc
echo
echo -n ' ├─'
echo -n '[ '
set_color normal
test -n $field_name
and echo -n $field_name
set_color -o brblack
echo -n ' ▶ '
set_color $retc
set_color $cust
echo -n $field_value
set_color $retc
echo -n ' ]'
end
set_color $retc
echo -n '─┬─'
echo -n '[ '
set_color -o red
echo -n (prompt_hostname)
echo -n ': '
if test "$USER" = root -o "$USER" = toor
set_color -o brred
else
set_color -o brwhite
end
echo -n $USER
set_color -o brblack
echo -n ' ▶ '
set_color -o brcyan
echo -n (pwd)
set_color $retc
echo -n ' ]'
# Virtual Environment
set -q VIRTUAL_ENV_DISABLE_PROMPT
or set -g VIRTUAL_ENV_DISABLE_PROMPT true
set -q VIRTUAL_ENV
and _nim_prompt_wrapper $retc '🐍 ' (basename "$VIRTUAL_ENV") cyan
# git
set prompt_git (fish_git_prompt | string trim -c ' ()')
test -n "$prompt_git"
and _nim_prompt_wrapper $retc (basename -s .git (git config --get remote.origin.url) 2> /dev/null) $prompt_git
# New line
echo
# Background jobs
set_color normal
for job in (jobs)
set_color $retc
echo -n ' │ '
set_color brown
echo $job
end
set_color normal
set_color $retc
echo -n ' ╰─> '
set_color normal
end
The general layout of my prompt:
─┬─[ hostname: user ▶ pwd ]
╰─> _
And blow is what I want instead of >:
─┬─[ hostname: user ]
├─[ pwd ]
╰─> _
OR
─┬─[ hostname: username ]
├─⎡ as_much_as_possible ⎤
├─⎣ the_rest_of_PWD ⎦
╰─> _
But, when $PWD is longer than the window's column size, the whole prompt is just >. I feel that using $COLUMNS should work, but I don't know how I can check the length of pwd before echoing it.
I DO NOT WANT TO USE prompt_pwd.
Thanks in advance! ;)

You can store whatever you want in a variable and then check it, modify it however you want and then echo it.
Here's a rough sketch:
set -l firstline '─┬─[' (prompt_hostname): $USER ▶ $PWD ']'
set -l secondline
if test (string length -- "$firstline") -gt $COLUMNS
# move $PWD to the second line
set firstline '─┬─[' (prompt_hostname): $USER ']'
set secondline '├─[' $PWD ']'
end
echo $firstline
echo $secondline
I DO NOT WANT TO USE prompt_pwd.
You very possibly do. It handles replacing $HOME with ~ (which saves quite a few columns) and does shortening to $fish_prompt_pwd_dir_length characters, or no shortening other than ~ if that's set to 0.
You can even adapt the shortening to $COLUMNS. From my prompt:
# Shorten pwd if prompt is too long
set -l pwd (prompt_pwd)
# 0 means unshortened
for i in $fish_prompt_pwd_dir_length 0 10 9 8 7 6 5 4 3 2 1
set pwd (fish_prompt_pwd_dir_length=$i prompt_pwd)
set -l len (string length -- $prompt_host_nocolor$pwd$last_status$delim' ')
if test $len -lt $COLUMNS
break
end
end

Related

Passing 'out' variables to function

I'm trying to make my fish_prompt fancier by having the colors of my username and host change depending on what they are. However, if this attempt fails, I'd rather leave the colors as defaults of $fish_color_[host|user] So far, this works:
function fish_prompt
# …
set -l color_host $fish_color_host
if command -qs shasum
set color_host (colorize (prompt_hostname))
end
# …
echo -n -s \
(set_color --bold $color_user) "$USER" \
(set_color normal) # \
(set_color $color_host) (prompt_hostname) \
' ' \
(set_color --bold $color_cwd) (prompt_pwd) \
(set_color normal) " $suffix "
end
function colorize
echo -n (printf "$argv" | shasum -ta 256 - | cut -c 59-64 | tr -d '\n')
end
At this point, I thought that this would look a lot cleaner if the shasum check were in colorize instead of being repeated in fish_prompt. I then tried this, figuring I might be able to pass the variable name if I single quoted it:
function fish_prompt
# …
set -l color_user $fish_color_user
colorize_more 'color_user' "$USER"
# …
end
function colorize_more -a what -a whence
if command -qs shasum
set "$what" (printf "$whence" | shasum -ta 256 - | cut -c 59-64 | tr -d '\n')
end
end
However, this doesn't appear to change $color_user in fish_prompt. I suspect that's because the set in colorize_more can't modify a variable that's local to the one in fish_prompt, as the color that should come out of colorize_more is a yellow instead of the green that I get from $fish_color_user.
How can I restructure my fish_prompt and accessory function(s) so that I have a colorize function that sets a variable to some value only if it is able to?
There are multiple possibilities here.
One is the "--no-scope-shadowing" flag to function
function colorize_more -a what -a whence --no-scope-shadowing
that will keep the outer local scope visible. This won't work with e.g. $argv, and if you need any variables they could potentially overwrite externally defined ones, so this is to be used with care.
Another is to define the variables as global instead - this has the disadvantage that they'll then stay defined and will conflict with any global variable of the same name.
Another is to output the value instead of assigning it.
E.g.
function colorize_more -a whence
if command -qs shasum
echo (printf "$whence" | shasum -ta 256 - | cut -c 59-64 | tr -d '\n')
end
end
set -l color_user (colorize_more $USER)
set -q color_user[1]; or set color_user $fish_color_user
# or you could let colorize_more output $fish_color_user if it wouldn't output anything else
Inspired by faho's comment of "Another is to output the value instead of assigning it", I ended up doing this:
function fish_prompt --description 'Write out the prompt'
# …
set -l color_host (colorize (prompt_hostname) "$fish_color_host")
set -l color_user (colorize "$USER" "$fish_color_user")
# …
end
function colorize -a what -a default -d 'Outputs a hex color for a string or, failing that, a default'
if command -qs shasum
echo -n (printf "$what" | shasum -ta 256 - | cut -c 59-64 | tr -d '\n')
else
echo "$default"
end
end

jboss-fuse-6.3.0.redhat-187 Fabric ssh script Error - Command not found: function

Created a Fabric Root
started ./fuse and then executed bellow command
fabric:create --wait-for-provisioning --verbose --clean --new-user admin --new-user-role admin --new-user-password admin --zookeeper-password zoopassword --resolver manualip --manual-ip 127.0.0.1
Started another fuse server ./fuse with ssh listening on 8102
Executed bellow command in the root console(fuse running at step 1 as root)
fabric:container-create-ssh --host 127.0.0.1 --user admin --password admin --port 8102 --new-user admin --new-user-password admin --resolver manualip --manual-ip 127.0.0.1 mqgateway
Then getting this Error :
--- command ---
#!/bin/bash function run { echo "Running: $*" ; $* ; rc=$? ; if [ "${rc}" -ne 0 ]; then echo "Command Failed:Error running installation script: $*" ; exit ${rc} ; fi ; }
function sudo_n { SUDO_NON_INTERACTIVE=`sudo -h | grep "\-n"` if [
-z "$SUDO_NON_INTERACTIVE" ]; then
sudo $* else
sudo -n $* fi }
function download { echo "Downloading: $1"; ret=`curl -C - --retry 10 --write-out %{http_code} --silent --output $2 $1`; if [ "${ret}"
-ne 200 ]; then
echo "Download failed with code: ${ret}";
rm $2; fi; }
function maven_download { echo "Downloading Maven Artifact with groupId: $2 artifactId: $3 and version: $4 from repository: $1"; export REPO=$1 export GROUP_ID=$2 export ARTIFACT_ID=$3 export VERSION=$4 export TYPE=$5 export TARGET_FILE=$ARTIFACT_ID-$VERSION.$TYPE
export GROUP_ID_PATH=`echo $GROUP_ID | sed 's/\./\//g'`
export ARTIFACT_BASE_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/`
if [[ "$VERSION" == *SNAPSHOT* ]]; then
export ARTIFACT_URL=`curl --location -C - --retry 10 --silent $ARTIFACT_BASE_URL | grep href | grep zip\" | sed 's/^.*<a href="//' | sed 's/".*$//' | tail -1` else
export ARTIFACT_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.$TYPE` fi
if [ -z "$ARTIFACT_URL" ]; then
export ARTIFACT_URL=`echo $REPO$GROUP_ID_PATH/$ARTIFACT_ID/$VERSION/$ARTIFACT_ID-$VERSION.$TYPE` fi
echo "Using URL: $ARTIFACT_URL" ret=`curl --location --write-out %{http_code} --silent --output $TARGET_FILE $ARTIFACT_URL` if [ "${ret}" -ne 200 ]; then
echo "Download failed with code: ${ret}"
rm $TARGET_FILE fi }
function update_pkgs() { if which dpkg &> /dev/null; then
sudo_n apt-get update elif which rpm &> /dev/null; then
sudo_n yum check-update fi }
function install_curl() { echo "Checking if curl is present." if which curl &> /dev/null; then
echo "Curl is already installed." else
echo "Installing curl."
if which dpkg &> /dev/null; then
sudo_n apt-get -y install curl
elif which rpm &> /dev/null; then
sudo_n yum -y install curl
fi fi }
function install_unzip() { echo "Checking if unzip is present." if which unzip &> /dev/null; then
echo "Unzip is already installed." else
echo "Installing unzip."
if which dpkg &> /dev/null; then
sudo_n apt-get -y install unzip
elif which rpm &> /dev/null; then
sudo_n yum -y install unzip
fi fi }
function install_openjdk_deb() { sudo_n apt-get -y install openjdk-7-jdk
# Try to set JAVA_HOME in a number of commonly used locations # Lifting JAVA_HOME detection from jclouds
for CANDIDATE in `ls -d /usr/lib/jvm/java-1.7.0-openjdk-* /usr/lib/jvm/java-7-openjdk-* /usr/lib/jvm/java-7-openjdk 2>&-`; do
if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then
export JAVA_HOME=$CANDIDATE
break
fi
done
if [ -f /etc/profile ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/profile" fi if [ -f /etc/bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/bashrc" fi if [ -f ~root/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> ~root/.bashrc" fi if [ -f /etc/skel/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/skel/.bashrc" fi if [ -f "$DEFAULT_HOME/$NEW_USER" ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> $DEFAULT_HOME/$NEW_USER" fi
sudo_n update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 17000 sudo_n update-alternatives --set java $JAVA_HOME/bin/java java -version }
function install_openjdk_rpm() { sudo_n yum -y install java-1.7.0-openjdk-devel
# Try to set JAVA_HOME in a number of commonly used locations # Lifting JAVA_HOME detection from jclouds
for CANDIDATE in `ls -d /usr/lib/jvm/java-1.7.0-openjdk-* /usr/lib/jvm/java-7-openjdk-* /usr/lib/jvm/java-7-openjdk 2>&-`; do
if [ -n "$CANDIDATE" -a -x "$CANDIDATE/bin/java" ]; then
export JAVA_HOME=$CANDIDATE
break
fi
done
if [ -f /etc/profile ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/profile" fi if [ -f /etc/bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/bashrc" fi if [ -f ~root/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> ~root/.bashrc" fi if [ -f /etc/skel/.bashrc ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> /etc/skel/.bashrc" fi if [ -f "$DEFAULT_HOME/$NEW_USER" ]; then
sudo_n "echo 'export JAVA_HOME=$JAVA_HOME' >> $DEFAULT_HOME/$NEW_USER" fi
sudo_n alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 17000 sudo_n alternatives --set java $JAVA_HOME/bin/java java
-version }
function install_openjdk() {
echo "Checking if java is present."
ARCH=`uname -m`
JAVA_VERSION=`java -version 2>&1`
if [[ $JAVA_VERSION == *1.7* ]]; then
echo "Java is already installed."
else
echo "Installing java."
if which dpkg &> /dev/null; then
install_openjdk_deb
elif which rpm &> /dev/null; then
install_openjdk_rpm
fi
fi }
function validate_requirements() { if ! which curl &> /dev/null; then
echo "Command Failed:Curl is not installed."; fi if ! which java &> /dev/null; then
echo "Command Failed:Java is not installed.";
exit -1; else
check_java_version fi }
function check_java_version() { JAVA_VERSION=`java -version 2>&1 | grep "[java|openjdk] version" | awk '{print $3}' | tr -d \" | awk '{split($0, array, ".")} END{print array[2]}'` if [ $JAVA_VERSION
-ge 6 ]; then
echo "Java version is greater than 1.6." else
echo "Command Failed:Unsupported java version: 1.$JAVA_VERSION.x found."
exit -1; fi }
function exit_if_not_exists() { if [ ! -f $1 ]; then
echo "Command Failed:Could not find file $1";
exit -1; fi local zipFile="$1" local size="$(du $zipFile | awk '{ print $1}')" if [ $size -lt 100 ]; then
echo "Command Failed: Zip archive is empty. Check $1";
exit -1; fi
}
function copy_node_metadata() { echo "Copying metadata for container: $1"; TARGET_PATH="./fabric/import/fabric/registry/containers/config/$1/" mkdir -p $TARGET_PATH ENCODED_METADATA=$2 echo $ENCODED_METADATA > ./fabric/import/fabric/registry/containers/config/$1/metadata.cfg }
function karaf_check() { KARAF_HOME=$1 INSTANCES_FILE=$KARAF_HOME/instances/instance.properties for i in {1..5};
do
if [ ! -f $INSTANCES_FILE ]; then
sleep 1
else
break
fi
done if [ -f $INSTANCES_FILE ]; then
for j in {1..5};
do
PID=`cat $INSTANCES_FILE | grep "item.0.pid" | awk -F "=" '{print $2}'`
if [ "$PID" = "" ]; then
sleep 1
else
break
fi
done
if ps -p $PID > /dev/null; then
echo "Fabric is started successfully"
else
echo "Command Failed: Karaf process ($PID) is not running"
fi else
echo "Command Failed:Could not find Karaf instance.properties" fi }
function replace_in_file { sed "s/$1/$2/g" $3 > $3.tmp rm $3 mv $3.tmp $3 }
function replace_property_value { echo "Setting value $2 for key $1 in $3" sed "s/$1[ \t]*=.*/$1 = $2/g" $3 > $3.tmp rm $3 mv $3.tmp $3 }
function configure_hostnames() { CLOUD_PROVIDER=$1 case $CLOUD_PROVIDER in
openstack-nova | ec2 | aws-ec2 )
echo "Resolving public hostname for ec2 node"
export PUBLIC_HOSTNAME=`curl http://169.254.169.254/latest/meta-data/public-hostname | sed 's/ /_/g'`
echo PUBLIC_HOSTNAME
;;
cloudservers | cloudservers-uk | cloudservers-us )
echo "Resovling public hostname for rackspace node"
PRIVATE_IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
export PUBLIC_HOSTNAME=`echo $PRIVATE_IP | tr . -`.static.cloud-ips.com
;; esac if [ ! -z ${PUBLIC_HOSTNAME} ]; then
LOOKUP_ADDRESS=`nslookup $PUBLIC_HOSTNAME > /dev/null | grep Address | tail -n 1 | cut -d " " -f 3 | sed 's/ /_/g'`
echo "Found hostname: $PUBLIC_HOSTNAME matching with address: $LOOKUP_ADDRESS"
echo "publichostname=$PUBLIC_HOSTNAME" >> etc/system.properties
cat etc/system.properties | grep -v 'local.resolver=' | grep -v 'global.resolver=' > etc/system.properties.tmp
mv etc/system.properties.tmp etc/system.properties
echo "local.resolver=publichostname" >> etc/system.properties
echo "global.resolver=publichostname" >> etc/system.properties
echo $PUBLIC_HOSTNAME > hostname
sudo_n cp hostname /etc/
export JAVA_OPTS="-Djava.rmi.server.hostname=$PUBLIC_HOSTNAME $JAVA_OPTS"
echo "RESOLVER OVERRIDE:publichostname" fi }
function find_free_port() { START_PORT=$1 END_PORT=$2 for port in `eval echo {$START_PORT..$END_PORT}`;do
if [[ $OSTYPE == darwin* ]]; then
# macosx has a different syntax for netstat
netstat -atp tcp | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$port" > /dev/null 2>&1 && continue || echo $port && break;
else
netstat -utan | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$port" > /dev/null 2>&1 && continue || echo $port && break;
fi done }
function wait_for_port() {
PORT=$1
for i in {1..5};
do
if [[ $OSTYPE == darwin* ]]; then
# macosx has a different syntax for netstat
netstat -an -ptcp | grep LISTEN | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$PORT" > /dev/null 2>&1 && break;
else
netstat -lnt | tr -s ' ' ' '| cut -d ' ' -f 4 | grep ":$PORT" > /dev/null 2>&1 && break;
fi
sleep 5;
done
return 0 }
function extract_zip { if ! which unzip &> /dev/null; then
jar xf $1 else
unzip -o $1 fi }
function generate_ssh_keys { if [ ! -f ~/.ssh/id_rsa ]; then
mkdir -p ~/.ssh
ssh-keygen -t rsa -N "" -f ~/.ssh/id_rsa fi }
run mkdir -p ~/containers/ run cd ~/containers/ run mkdir -p mqgateway run cd mqgateway validate_requirements cp /tmp/fabric8-karaf-1.2.0.redhat-630187.zip fabric8-karaf-1.2.0.redhat-630187.zip if ! jar xf fabric8-karaf-1.2.0.redhat-630187.zip &> /dev/null; then rm fabric8-karaf-1.2.0.redhat-630187.zip ; fi if [ ! -f fabric8-karaf-1.2.0.redhat-630187.zip ] && [ ! -s fabric8-karaf-1.2.0.redhat-630187.zip ] ; then maven_download http://127.0.0.1:8181/maven/download/ io.fabric8 fabric8-karaf
1.2.0.redhat-630187 zip exit_if_not_exists fabric8-karaf-1.2.0.redhat-630187.zip run extract_zip fabric8-karaf-1.2.0.redhat-630187.zip run cd `ls -l | grep fabric8-karaf | grep ^d | awk '{ print $NF }' | sort -n | head -1` run mkdir -p system/io/fabric8/fabric8-karaf/1.2.0.redhat-630187 run cp ../fabric8-karaf-1.2.0.redhat-630187.zip system/io/fabric8/fabric8-karaf/1.2.0.redhat-630187/ run rm ../fabric8-karaf-1.2.0.redhat-630187.zip run chmod +x bin/* cat >> etc/system.properties <<'END_OF_FILE' global.resolver=localhostname END_OF_FILE replace_property_value "karaf.name" "mqgateway" etc/system.properties replace_property_value "importDir" "fabric" etc/io.fabric8.datastore.cfg replace_property_value "felix.fileinstall.filename" "file:\/C:\/Fabric\/root\/etc\/io.fabric8.datastore.cfg" etc/io.fabric8.datastore.cfg replace_property_value "component.name" "io.fabric8.datastore" etc/io.fabric8.datastore.cfg replace_property_value "gitRemotePollInterval" "60000" etc/io.fabric8.datastore.cfg replace_property_value "service.pid" "io.fabric8.datastore" etc/io.fabric8.datastore.cfg BIND_ADDRESS=0.0.0.0 SSH_PORT="`find_free_port 8101 65535`" RMI_REGISTRY_PORT="`find_free_port 1099 65535`" RMI_SERVER_PORT="`find_free_port 44444 65535`" JMX_SERVER_URL="service:jmx:rmi:\/\/${BIND_ADDRESS}:${RMI_SERVER_PORT}\/jndi\/rmi:\/\/${BIND_ADDRESS}:${RMI_REGISTRY_PORT}\/karaf-mqgateway" HTTP_PORT="`find_free_port 8181 65535`" replace_property_value "sshPort" "$SSH_PORT" etc/org.apache.karaf.shell.cfg replace_property_value "sshHost" "$BIND_ADDRESS" etc/org.apache.karaf.shell.cfg replace_property_value "rmiRegistryPort" "$RMI_REGISTRY_PORT" etc/org.apache.karaf.management.cfg replace_property_value "rmiServerPort" "$RMI_SERVER_PORT" etc/org.apache.karaf.management.cfg replace_property_value "rmiServerHost" "$BIND_ADDRESS" etc/org.apache.karaf.management.cfg replace_property_value "rmiRegistryHost" "$BIND_ADDRESS" etc/org.apache.karaf.management.cfg replace_property_value "org.osgi.service.http.port" "$HTTP_PORT" etc/org.ops4j.pax.web.cfg replace_in_file "8181" "$HTTP_PORT" etc/jetty.xml cat >> etc/system.properties <<'END_OF_FILE' minimum.port=0 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' maximum.port=65535 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE'
END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' preferred.network.address=127.0.0.1 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.url = 127.0.0.1:2181 END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.password = ZKENC=em9vcGFzc3dvcmQ= END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' zookeeper.password.encode = true END_OF_FILE cat >> etc/system.properties <<'END_OF_FILE' agent.auto.start=true END_OF_FILE sed 's/featuresBoot=/&fabric-agent,fabric-git,/' etc/org.apache.karaf.features.cfg > etc/org.apache.karaf.features.cfg.tmp mv etc/org.apache.karaf.features.cfg.tmp etc/org.apache.karaf.features.cfg sed 's/repositories=/&http:\/\/127.0.0.1:8181\/maven\/download\/,/' etc/org.ops4j.pax.url.mvn.cfg > etc/org.ops4j.pax.url.mvn.cfg.tmp mv etc/org.ops4j.pax.url.mvn.cfg.tmp etc/org.ops4j.pax.url.mvn.cfg generate_ssh_keys configure_hostnames none cat > bin/setenv <<'END_OF_FILE' export JAVA_OPTS=" -XX:+UnlockDiagnosticVMOptions
-XX:+UnsyncloadClass -server"
END_OF_FILE nohup bin/start & karaf_check `pwd` wait_for_port $SSH_PORT wait_for_port $RMI_REGISTRY_PORT
--- output --- Command not found: function
--- error ---
------
SSH containers should be created on Remote machines.An SSH container is just a Fabric container that is running on a remote host on your local network,
where that host is accessible through the SSH protocol. This section describes some basic administration tasks for these SSH containers.
Please refer https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.3/html/fabric_guide/chapter-fabric_container#ContSSH
If you want to create containers on the same machine (local host) create child containers
https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.3/html/fabric_guide/chapter-fabric_container#ContChild
Creating ssh container
fabric:container-create-ssh --host remotehost --user user1 --password pass1 --jvm-opts="-Djava.rmi.server.hostname=remotehost" --profile fabric fabric-eu03

sed - Separate quotes and arguments

So, I'm trying to get a script I'm working on to run another script in different directories with different arguments as defined in a text file.
Here's part of my code:
for bline in $(cat "$file"); do
lindir=$()
linarg=$()
echo "dir: ${lindir}"
echo "arg: ${linarg}"
done
Let's say I have a line in file that says this:
"./puppies" -c=1 -u=0 -b=1
How can I get an output of ./puppies for lindir and an output of -c=1 -u=0 -b=1 for linarg?
lindir="$( cut -d ' ' -f 1 <<<"$bline" )"
linarg="$( cut -d ' ' -f 2- <<<"$bline" )"
That is
while read -r bline; do
lindir="$( cut -d ' ' -f 1 <<<"$bline" )"
linarg="$( cut -d ' ' -f 2- <<<"$bline" )"
printf "dir: %s\n" "$lindir"
printf "arg: %s\n" "$linarg"
done <"$file"
If you're in a shell that doesn't understand "here-strings":
lindir="$( printf "%s" "$bline" | cut -d ' ' -f 1 )"
linarg="$( printf "%s" "$bline" | cut -d ' ' -f 2- )"

how to send input to a daemon in linux

#!/bin/bash
. /etc/init.d/functions
NAME=foo
DIR=/home/amit/Desktop
EXEC=foo.pl
PID_FILE=/var/run/foo.pid
IEXE=/etc/init.d/foo
RUN_AS=root
if [ ! -f $DIR/$EXEC ]
then
echo "$DIR/$EXEC not found."
exit
fi
case "$1" in
start)
echo -n "Starting $NAME"
cd $DIR
/home/amit/Desktop/foo.pl
echo "$NAME are now running."
;;
stop)
echo -n "Stopping $NAME"
kill -TERM `cat $PID_FILE`
rm $PID_FILE
echo "$NAME."
;;
force-reload|restart)
$0 stop
$0 start
;;
submit)
echo $2 >> /tmp/jobs
;;
*)
echo "Use: /etc/init.d/$NAME {start|stop|restart|force-reload}"
exit 1
;;
esac
exit 0
i have created a daemon with start and stop options(service foo start/stop) and it works fine. Now I want to send an input to the dameon. something like "service foo submit [argument]" . I want to to know - if user types "service foo submit alexander" , how alexander can be sent to the running daemon ?
If I get the question right - just as you already use positional var $1 you can supply the rest of the arguments to the command as well, i.e.:
"your_start_up_script" [switch to the script as $1] [arg 2 will be accessible via $2] [arg 3 will be accessible via $3]
Then inside script you do:
case "$1" in
start)
echo -n "Starting $NAME"
cd $DIR
/home/amit/Desktop/foo.pl "$2" "$3"

NetworkManager dispatcher script

scripts in /etc/NetworkManager/dispatcher.d will got exec and parameters will be passed to the scripts by NetworkManager.
One of my laptop BIOS is malfunctioning, I have to manually sync the time, and do system upgrade BTW. I am working with a script to automate this task.
Here's the script:
#!/bin/sh
IF=$1
STATUS=$2
if [ "$STATUS"x != 'up'x -o "$(date +%Y)" -gt "2012" ] ;then
exit
fi
logger "==$0=="
wait_for_process(){
PNAME=$1
PID=`pgrep $PNAME`
while [ -z "$PID" ];do
logger "waiting $1 running for another 3 sec.."
sleep 3;
PID=`pgrep $PNAME`
done
logger "$1 is running!"
}
wait_for_process nm-applet
wait_for_process lxpanel
export DISPLAY=$(echo $DISPLAY | cut -c -2)
if [ -z $DISPLAY ];then
export DISPLAY=:0
fi
#below cmd will yield null string for $user
user=$(who | grep "$DISPLAY" | awk '{print $1}' | tail -n1)
#so I have to hardcode the user name:(
user=xxx
export XAUTHORITY="/home/$user/.Xauthority"
logger "Display $DISPLAY user $user"
su $user -c "xterm -e 'sudo /usr/bin/ntpd -qdg && sudo yaourt -Syua' &" || logger "cannot run xterm"
(the script is invoked before x window, run as root)
user=$(who | grep "$DISPLAY" | awk '{print $1}' | tail -n1) cannot find the login user name. But it works in xterm.
Can someone help?
I am using archlinux i686 + openbox + lxpanel
edit:
I want to find the real login user name, while the script is run by root.
Are you looking for the name of the user running the script? How about:
user=$( id -un )