I'm using bash to feed gnuplot from a script. How you pop up only one window? Let say you run
#!/bin/bash
for((i=1;i<6;i++)) do
echo "plot sin(x)"
done | gnuplot -persist
you will get 5 windows of the same plot. Is there an option to get only one?
There was a mistake above. That wasn't exactly the kind of run-time i'm doing. Is more like runing the next script, say, 5 times
#!/bin/bash
echo "plot sin(x)"
I just realized that what I want to do is kill the latest gnuplot process before make the new one.
Sorry for that. I'm sooo tired today :D
the gnuplot x11 terminal uses a separate program called gnuplot_x11 for displaying the results. From the help
The `xlib` terminal driver supports the X11 Windows System. It generates
gnuplot_x11 commands, but sends them to the output file specified by
`set output '<filename>'`. `set term x11` is equivalent to
`set output "|gnuplot_x11 -noevents"; set term xlib.`
`xlib` takes the same set of options as `x11`.
So, if you want to kill plots that are remaining after a gnuplot -persist, it should suffice to killall gnuplot_x11.
You might be interested in the iteration capabilities available in newer versions of Gnuplot (see the section Iteration in the user's guide)
What about the following:
echo `for((i=1;i<6;i++))
do
echo 'plot sin(x)'
done` | gnuplot -persist
In one script one can
echo "set grid" > gpfile
tail -f gpfile | gnuplot '-'
then in another process one can write any gnuplot commands into the gpfile
echo "plot \"whatever\" " >> gpfile
sleep 3
echo "replot" >> gpfile
...etc
Its useful for realtime process control display, where some status file
is being updated at intervals.
Related
I want to be able to interactively get output from the terminal in a way similar to a hereDOC. Ie I want the user to be able to type multiple lines, then have that information passed into a file with all the formatting maintained. Something like this.
echo "Type your message below. To finish the letter type DONE by itself on a line"
file=mktmp
cat << DONE > $file
obviously this doesn't work, because the EOF is found before DONE. I thought about passing the user to something like VIM, but my less computer savy coworkers have a hard time with vim/emacs/nano.
You need to use an editor; standard input is just a stream of bytes, not an editor. However, you don't have to hard-code a specific editor. EDITOR is a standard environment variable meant to allow your script's caller to choose which editor is used.
: ${EDITOR:?Please set the environment variable EDITOR to the editor of your choice}
echo "Type your message below, then save and exit your editor."
"$EDITOR" "$file"
EDITOR is typically set by the user in their shell configuration file, but can be set on-demand when you run your script.
$ EDITOR=nano yourScript.sh
okay, so I came up with this, but please help me find something better or improve on it.
echo "Type your message below, to finish the letter press CTL+D"
mapfile message
file=`mktemp`
for x in `seq 0 ${#message[#]}`
do printf "${message[$x]}" >> $file
done
cat $file
I'm trying to make a bash script in combination with gnuplot.
I'm using an input file 'input.list' containing the single-column list of files to be analyzed with gnuplot.
I'm using a following bash script:
#!/bin/bash
while read -r line
do
...
#Other operations on files
...
gnupinp=$line
gnuplot -e "input='${gnupinp}'; plot input u 1:2; pause -1"
done < input.list
There are two issues probably connected:
When first file from the list is analyzed the plot is created but the pause -1 seems to be neglected while pause 1 works fine.
No matter if I use pause -1 or pause 1 the script fails starting from the #Other operations on files part when the second file from the list is executed.
The same behavior can be obtained when I use system 'sleep 1' command in gnuplot.
When I neglect pause command the gnuplot scripts are preformed properly for all listed files.
thanks in advance for any help
You are using the standard input in two competing ways: feeding the data to read, and to gnuplot's pause -1.
If you want the user to be able to interact with gnuplot by pressing return after the graph is plotted, you have to use some other way than stderr to feed your script with data, e.g. read from a file.
I can't run my gnuplot script in background within a shell script. Something like in following example
#!/bin/bash
for i in 1 2 3
do
run gnu_script($i).p
done
As per the answer given by Christoph I could able to do it. But still the figure windows are coming and not letting me to do anything in the computer.
What about something simple as
for i in 1 2 3
do
gnuplot script$i.gp &
done
That assumes, that you have different scripts script1.gp, script2.gp and script3.gp.
If you have only a single script and want to pass the iteration number to it, you could do it with
for i in 1 2 3
do
gnuplot -e "i=${i}" script.gp &
done
A simple gnuplot script script.gp for testing this is
set terminal pngcairo
set output sprintf('script%d.png', i)
plot x title sprintf('%d', i)
pause 10
The pause 10 makes gnuplot pause for 10 seconds.
I'm trying to show an animation using gnuplot
I got the following script:
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
a=a+1
if ( a<b ) reread
that I execute using
a = 0
b = 100
load "a.plot"
it works, but is there a way to execute all of this using only 1 command from a shell?
Alternatively is there a way to integrate the variable definitions into the .plot file so that I can simply execute it? I tried different things like echo 'a=0'|gnuplot etc but it doesn't seem to actually define the variable correctly
thanks
You can use a do for loop.
do for [a = 0:100] {
plot ”heat1d.txt ” using 1:2 every :::a::a
pause 0.01
}
The default terminal on linux is usually wxt, and it has the raise option, which will change the focus to the plot window at every iteration. This will make it difficult if not impossible to stop the animation.
I suggest to put noraise as the terminal option. For example, you can put the following line at the beginning of the script:
set term wxt noraise
Now, if you want to stop the animation halfway, press CtrlC on the gnuplot terminal.
You can pass -e as a commandline argument. For example, if you have the script:
#script test.gp
print foo,bar
Then you could run it with gnuplot using:
gnuplot -e "foo=1;bar=2" test.gp
In your case, it looks like you could accomplish nearly what you want by invoking your script as:
gnuplot -e "a=0;b=100" a.plot
I have some long running scripts with breaks requiring input/interaction to continue but when I switch to another window I'd like to be notified (by sound) that a task is complete and now awaiting input.
I would prefer to be able to play an audio clip (*.mp3, *.ogg, etc.) but wouldn't care if the only solution is to make the PC Speaker beep noise.
Any ideas? I'm open to any CLI utilities I can install that play sounds that in turn I can execute when needed.
FYI: My System is running WinXP Pro.
UPDATE: Doh! My Windows > Control Panel > Sounds > Default Beep: was set to (none). Grrr...
Problem solved.
This will make a beep from within bash
echo -en "\007"
Try this:
echo ^G
(^G is obtained by ctrl+G).
Note: you can't copy and paste this code in a batch file, it won't work. To obtain a ^G character in a file, type in a cmd window:
echo ^G > beep.txt
(again, ^G is obtained by ctrl+G).
Then you'll have a file named beep.txt, open it with notepad, there will be a square character. This is our ^G once it is saved in a file.
You can then copy and paste it in a batch file to make a sound (don't forget to put "echo" in front of it).
spd-say
sleep 2; spd-say 'get back to work'
Infinite loop with -w if you need extra motivation:
sleep 2; while true; do spd-say -w 'get back to work'; done
or if you prefer the carrot:
sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; done
Pre-installed on Ubuntu 14.04 via the package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?
See also: https://askubuntu.com/questions/277215/how-to-make-a-sound-once-a-process-is-complete
Also add a popup
This combo is a life saver, b stands for beep:
b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )
and then:
super-slow-command;b
If I'm somewhere in the room, I'll hear it and know that the long job is done.
Otherwise, I'll see the popup when I get back to my computer.
Related:
How to show a GUI message box from a bash script in linux?
https://superuser.com/questions/345447/how-can-i-trigger-a-notification-when-a-job-process-ends
https://askubuntu.com/questions/409611/desktop-notification-when-long-running-commands-complete
Listen to your cooler
I'm joking of course, but for compilation I noticed that I use often use this queue subconsciously. When the cooler stops humming for a while, it means that the compilation is over!
I know your question was for Window but just putting this here for any Mac OSX users who come across this article. OSX 10+ comes with the say command:
say "I'm done"
For example:
sleep 5 && say "I'm done waiting 5 seconds"
By setting this variable as follows
PROMPT_COMMAND="echo -en '\a'"
then bash will beep every time it shows the prompt. When you do not need it anymore,
unset PROMPT_COMMAND
To play the system sound from Windows command line you can run:
rundll32 user32.dll,MessageBeep
It should work on all version of Windows.
copy con beep.bat [Enter]
#echo off [Enter]
echo [Ctrl+G] [Enter]
[Ctrl+Z] [Enter]
beep.bat [Enter]
Simple answer without ^G
echo -en "\007"
In my bash profile I've added a BEEP to the script using #GregReynolds solution above then added this to PS1:
GREEN="\[\033[0;32m\]"
BEEP=$(echo -en "\007")
export PS1="$GREEN : ${BEEP}"
source ~/.bash_profile - you should hear the beep after the command prompt returns
I have git-autocomplete on usually so I've provided a much simplified version above