I'm trying to create an "alias" to run a server in a separate terminal, then after a few seconds open its client, this is the command I'm trying:
alias kingp='xterm -e sudo /opt/king-phisher/KingPhisherServer -L INFO -f /opt/king-$/king-phisher/server_config.yml; /opt/king-phisher/KingPhisher'The problem with this is that it does not run the second command until I close the server (CTRL+C), and them it runs the client normally, I've tried with & and && at the end of the server command to no avail, it seems like the server, even being run with -e is still not liberating the terminal for the other command to run, I've been successful with -e before and have no idea why in a alias it does not work, anyone can help me? thank you very much guys.
21 Answer
The problem is that the alias is first interpreted by Bash, and then by XTerm.
Bash interprets the whole alias as two separate commands: xterm -e sudo /opt/king-phisher/KingPhisherServer -L INFO -f /opt/king-$/king-phisher/server_config.yml and /opt/king-phisher/KingPhisher, and the commands are executed one after the other in the current shell.
Using & instead of ; won't help, because Bash will still interpret &; escaping ; or & won't help either, because XTerm has no notion of Bash syntax, and will pass either ; or & as an argument to /opt/king-phisher/KingPhisherServer (along with the remainder of the command, /opt/king-phisher/KingPhisher).
The only solution is to tell XTerm to invoke Bash and let Bash do the parsing:
alias kingp="xterm -e bash -c 'sudo /opt/king-phisher/KingPhisherServer -L INFO -f /opt/king-$/king-phisher/server_config.yml & /opt/king-phisher/KingPhisher'"Unless you user doesn't need to provide a sudo password in order to run /opt/king-phisher/KingPhisherServer, this will lead to the server not starting because of the sudo command being backgrounded before being able to read the password; see here for possible solutions: How do I run a sudo command needing password input in the background?.