What you are trying to do is not possible that way.
Note that there are always two sides to that: The client side and the server side. Is the script on the client computer or on the server?
If it's on the client: You as the visitor are only seeing an HTML website. onClick
will only be able to launch JavaScript (or other scripting languages), but not any arbitrary shell script that resides on your computer. HTML scripts only run in the browser and can only do limited things. Most importantly, they can't interact with your computer.
Think about it: How would the browser know how to open the file? Don't you think this would be a security issue as well – a plain website triggering the execution of scripts on a client's computer? What if there was something like onClick('rm -rf /home/user')
?
An alternative would be to run a Java applet, if you want code to be executed on the client, but this not exactly the same and it's something really complicated. I don't think it's necessary to explain this in detail.
If the script is on the server: If you want to run a script on the server side and have the user trigger its execution, then you need to use a server side programming language. Just HTML won't do it, because it's more or less a static file. If you want to interact with the server, you could for example use PHP.
It has the exec
function to run a command line script that is stored on the web server. So basically, you could write exec('/path/to/name.sh');
and it would run the script on the server.
However, just putting this into onClick
is not enough here. If you don't know about PHP and server side web programming yet, you might want to read a few tutorials first and then come back with a more specific question.
If you have a php file with the appropriate exec(...)
command, make sure the script has execute permissions set not only for the user but also for the group the web server is in, so in the simplest case just 777
.
In case of trouble check for the return value of the script with echo exec(...);
to see if there are any errors.
You can also run the script from the command line and not from the browser with php /path/to/file.php
.
Per the documentation, when you create a detached session (new-session -d
), it defaults to a size of 80×24. If you attach with a terminal window that is actually 24 lines high (or 25, since tmux uses one for a status line), then you should find that the below-Vim pane does in fact end up with just five lines.
The problem comes when you attach to the session with a terminal window that is much taller than 24 lines. When you do this, tmux resizes the panes to fill the full terminal window. The lower pane grows past its original five lines when this happens.
One way to work around this problem is to create the detached session with an initial size that matches that of the terminal window from which you will eventually attach to the session. One semi-portable way to do this is to parse the output of stty size
(some shells also provide LINES and COLUMNS parameters (especially when in interactive mode), but these parameters are not always available and reliable in shell scripts).
set -- $(stty size) # $1 = rows $2 = columns
tmux -2 new-session -d -s "$SESSION" -x "$2" -y "$(($1 - 1))" # status line uses a row
The failed to connect to server: Connection refused
message comes from your tmux has-session
command. It is reporting that it there is no existing server. Since you are only interested in the exit code, you can probably just send the output to /dev/null
to avoid seeing it at all. You can also put the command directly into the if
statement:
if tmux has-session -t "$SESSION" 2>/dev/null; then
⋮
fi
Incidentally, you should almost always put your parameter expansions in double quotes (to avoid word splitting and glob expansion). You only have the one parameter and its value (copied from USER
) is (usually) probably safe not to quote, but it is a good habit to always quote your expansions in almost all contexts.
Best Answer
You can do serverside scripting in bash without problem.
Here a short tutorial how to do it: http://www.yolinux.com/TUTORIALS/BashShellCgi.html