Combine multiple commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Combine multiple commands
# 1  
Old 11-24-2016
Combine multiple commands

I have the following sh-script:

Code:
    konsole -T todo -e vi todo.txt &
    konsole -T window1 -e ssh user@server &
    konsole -T window2 -e ssh user@server2 -e cd directory &

The first two lines are working fine. The first opens a txt-file, the second opens a ssh-connection.
The third line should open a ssh-connection and then go to a dirctory, but it does not work. Can someone please tell me if it is possible to combine these two command in a script ?


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-24-2016 at 04:57 AM.. Reason: Added CODE tags.
# 2  
Old 11-24-2016
Not being familiar with konsole, I'd guess you could combine several commands in a "list", i.e. adding them after another separated by semicolons, eventually enclosed in (double) quotes. On top, ssh does allow to specify a command as a parameter. Did you consider that?
# 3  
Old 11-24-2016
Are you opening a remote session and then changing directory on that remote session? If you are you are doing it wrong as the -e option to ssh is not a "run this shell command" option.

Are you trying to keep the konsole open after the remote session closes, but change directory?

Andrew

Last edited by apmcd47; 11-24-2016 at 07:39 AM.. Reason: sorry, I misread the original posting.
# 4  
Old 11-25-2016
From the 'konsole' man page:

-e command

Execute command instead of the normal shell.


This option will catch all following arguments passed to Konsole, and execute it as command. So this option should always be used as the last option.

From this, I would conclude that in your last example konsole is actually executing the command

Code:
ssh user@server2 -e cd directory

which should cause an error message to be displayed (which you probably don't see, because the konsole window will close too quickly).
# 5  
Old 11-25-2016
@Andrew

Quote:
Are you opening a remote session and then changing directory on that remote session? If you are you are doing it wrong as the -e option to ssh is not a "run this shell command" option.
So what is the right way then ? Can you give me a few keywords ?

Quote:
Are you trying to keep the konsole open after the remote session closes, but change directory?
Yes, I wanna keep the konsole open and then work in it.
# 6  
Old 11-25-2016
One wonders what the point of changing directory is supposed to be. If that is all you do, then then you command will complete and the ssh will terminate putting you back to the client and you have achieved nothing except you would get an error if the directory was not accessible.

What are you really trying to do? Some context might help us understand your real purpose.



Kind regards,
Robin
# 7  
Old 11-25-2016
@rbatte1: I guess the OP poster wants a new console window opened, which is logged into a different host AND placed in a certain directory - at least this would make sense, but we don't know for sure.

Of course there are several ways to achieve this, but unless we don't know the exact requirements, there is no point in making suggestions.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combine 2 Commands

Hello, I have the following code. I wonder if it can be combined into 1 command. y=`ls -1| tail -n 1` m=${y%.abc} Thank you. (3 Replies)
Discussion started by: april
3 Replies

2. Shell Programming and Scripting

Combine two awk commands

Hi, Can someone please guide me how to combine the following two awk calls in one? I noticed that it is very often situation for me, and I think that it can be replaced with one awk call. The question is more general, not the exact one. echo "A B C/D" | awk '{print $3}' | awk -F/ '{print... (4 Replies)
Discussion started by: mirusnet
4 Replies

3. Shell Programming and Scripting

Combine awk commands into one

my code: gawk 'NR>'"${LASTLINENUM}"' && NR<='"${LINEENDNUM}"'' ${LOGFILE} | gawk '{l=$0;} /'"${STRING1}"'/ && /'"${STRING2}"'/ {for (i=NR-'"${BEFOREGLAF}"'; i<=NR+'"${AFTERGLAF}"'; i++) o=i; t++;} END { for(i=1; i<=NR; i++) if (o) print l; print t+=0;}' i would like to combine this into one... (5 Replies)
Discussion started by: SkySmart
5 Replies

4. Shell Programming and Scripting

Csh - how to combine multiple commands in one line

Hey everyone, I am working in an environment where the different users can use ksh or csh. My situation is that I need the same result with one single command line. I am searching for the real path the file is in. My ksh input and output ts2:ts2adm> cd $(dirname $(which sapcontrol)); pwd -P... (2 Replies)
Discussion started by: h1kelds
2 Replies

5. Shell Programming and Scripting

Combine multiple awk commands

Hi Team, I am getting input like below $ ps -ef | grep pmon | grep -v asm | grep -v grep oracle 3246 1 0 00:03 ? 00:00:01 ora_pmon_racora1 oracle 4367 1 0 00:03 ? 00:00:01 ora_pmon_test1 oracle 6893 1 0 00:03 ? 00:00:01 ora_pmon_gipora1... (6 Replies)
Discussion started by: kamauv234
6 Replies

6. Shell Programming and Scripting

Can I combine these two commands into one?

sed -e :a -e 's/<*>//g;/</N;//ba' a2.html -removes html tags and sed -i 's/YOURS TRULY/Joe Bob/' a2.html Replaces a string with another string can i make it into one string? (2 Replies)
Discussion started by: boyboy1212
2 Replies

7. Shell Programming and Scripting

Combine two lists From Multiple Grep commands.

I'm working with a file with an xml structure. I'd like to parse it down to just the bits i want. Here is and example of the file <message id="96352877" method="status"> <date rfc="Sat, 12 Mar 2011 16:13:15 -0600" unix="1299967995" /> <services> <service id="facebook"... (4 Replies)
Discussion started by: Erulisseuiin
4 Replies

8. Shell Programming and Scripting

nawk, combine commands

How would I combine two nawk commands together without calling up nawk twice. Just like the sed -e command nawk '$3>=from&&$3<=to' from="$STIME" to="$ETIME" | nawk '{$5="";$6=""}1' (2 Replies)
Discussion started by: numele
2 Replies

9. UNIX for Dummies Questions & Answers

Combine commands

Hi, i tried to combine grep with find and it didnt work grep 'find dirname filename" i also would like that the file will be sorted in the way. thanks a lot. (2 Replies)
Discussion started by: Spoiler
2 Replies

10. Shell Programming and Scripting

Combine Two Commands Output

How i can combine output of two commands in one file.......i tried this but it is not working although each command is working good seperately..... head -1 filename | tail -1 filename i think there is problem with command concatenator? (16 Replies)
Discussion started by: 33junaid
16 Replies
Login or Register to Ask a Question