0

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.

  • 1
    IMHO aliasis are nice for simple commands, but as the commands get more complex, better to run a script. Is there some reason you need to run xterm here ? try alias kingp='sudo /opt/king-phisher/KingPhisherServer -L INFO -f /opt/king-$/king-phisher/server_config.yml; /opt/king-phisher/KingPhisher` I am not sure where you want an & but your problem is likely due to calling xterm. If you write a script, however, your alias is simply alias kingp='sudo /path/to/script – Panther Apr 5 '16 at 12:47
  • Thanks I'm trying with a script but the server keeps executing one after another, it enters a infinity loop and never jumps to the next command, I think it has something to do with the parammeters that are being passed to the server (the -L etc..), gonna keep digging, thank you fort your help :) – w1r3dh4ck3r Apr 5 '16 at 15:06
0

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?.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.