Bash Beginner
Bash 4.3.46(1)-release (x86_64-pc-linux-gnu) @ Ubuntu MATE
I wrote a little Bash script called work. It uses a case statement for its main menu, listing several options. Option one is the function fam, fping asset monitor, a simple while loop that pings a list of IP addresses. While I have the main menu of the work script open in terminator, I want to launch this while loop in a separate terminator window of a certain size. Is this possible? Meanwhile, I copied the while loop (fam) to its own file in /usr/local/bin, and currently start fam with Code:
terminator -b --geometry=186x450 -x fam &>/dev/null & Code:
fam() { |
i think your current solution is acceptable.
you could also try starting the new window from within the fam function: Code:
fam() { you will have to fix the single quotes inside the single-quoted script. |
since ondoho's solution might cause some issues with quotes, I thought... maybe it can be done differently.
With a here-document; Due to not having a terminator here, I used konsole instead, but the idea remains; it kind of works too: Code:
scrippie=$(cat <<_EOF |
1 Attachment(s)
Thank you both.
Attempting Code:
terminator -x sh -c 'while true; do'... /usr/local/bin/work: line 81: syntax error near unexpected token `do' /usr/local/bin/work: line 81: ` terminator -x sh -c while true; do' I could have easily messed up the quoting. Will google more and keep trying. Here is what I have at the moment for the heredoc, which does indeed work. Somewhat. :) Code:
#!/usr/bin/env bash Code:
** (terminator:14510): WARNING **: Binding '<Shift><Control><Alt>a' failed! * Edit 2: Will keep reading and playing around until something sticks. Thanks again! |
Quote:
sed can usually use double quotes as well. |
The syntax error (unexpected token do) I had at first, that's why I preceded the "${scrippie}" with /bin/bash.
|
Code:
try that ... I do not know if you should pipe | that or not wouldn't hurt to try. I'm signing off or I've a tried it before posting.. so I'll just leave you with that idea to try instead. Code:
terminator -x sh -c | while [ true ] ; |
Heredoc method
Code:
#!/usr/bin/env bash - Opens a new terminator window with a $ prompt and a blinking cursor - The following error displays in the parent window: Code:
** (terminator:29590): WARNING **: Binding '<Shift><Control><Alt>a' failed! - The same bind hide_window key error displays in the parent terminal but - A new terminator window opens - The attached image in post #4 above shows what the new terminator window displays when using -x sh -c. Items in the 3rd column are asset tags. Two other things with the here document that didn't work: 1. Modifying mainMenu option 1 to read -x /bin/bash "${fam}" instead of -x sh -c...
2. -e /bin/bash "${fam}" made terminator barf a wall of text all over the parent window. But expansion and sed appear to have worked. Code:
Usage: terminator [options] Non-heredoc method Single quotes for sed were changed to double quotes. Code:
#!/usr/bin/env bash - New terminator window opens and closes too fast to see if it displays anything The same results happen if -x sh -c is replaced with -e sh -c or -x /bin/bash. Using -e /bin/bash summons wall barf. Unlike in the heredoc version of the script, it appears that neither expansion nor sed worked. Code:
terminator: error: Additional unexpected arguments found: ['while true; do\n\t\ttput clear\n\t\tfor ip in "${list1[@]}" "${list2[@]}"; do\n\t\t\tassettag=$(grep "$ip" <"$workdir"/ovpnip.txt | sed -e "s/,.*//")\n\t\t\tif ! fping -c 2 "$ip" &>/dev/null; then\n echo -e "\\e[31m- DN "$assettag" \\e[96m@ \\e[31m"$ip" -\\e[96m"\n else\n echo -e "\\e[32m+ UP "$assettag" \\e[96m@ \\e[32m"$ip" +\\e[96m"\n\t\t\tfi\n\t\tdone\n\t\techo -e "\\nLooping heartbeat in...\\n"\n\t\tfor i in {9..1..1}; do\n\t\t\techo -ne " ...$i...\\n" && sleep 1\n\t\tdone\n\tdone'] |
1) don't worry about the terminaltor keybind warning.
2) if you use the method i suggested, i think it doesn't know anything about the variables you use, i.e. list1, list2 and workdir, and therefore probably errors out. you can pass them as command line options. in post #1 you wrote that you had a working solution which had the script as a separate file. i answered that that solution is acceptable imo. you since edited post #1. please don't do that. so, again: you had a working solution. i understand you weren't happy with it because it's somewhat inelegant? |
1) Yes, warning not error, my mistake.
2) Yes, and many thanks! I edited post #1 to include the comment that lines in ovpnip.txt read AssetTag,IPAddress, for a bit of clarification. :) I guess I'm satisfied with the current solution, it does work after all. Just curious if there was a way to launch that function in a new terminator window from an existing session. Easy enough to do if the new window is a command + a few options, but I couldn't find examples of anything as lengthy as that while loop used in that way. Edit: Piping terminator -b --geometry=186x450 -x /bin/bash | while true; do at the start of the function spawns a new window with the expected PS1 prompt, but the fam function runs inside the parent terminal. |
This works with XTerm.
Code:
if [[ -n "$DISPLAY" ]] && [[ -n "$WINDOWID" ]] ; then |
All times are GMT -5. The time now is 08:32 PM. |