Results 1 to 4 of 4

Thread: Running two commands at the same time in bash script

  1. #1
    Join Date
    Oct 2021
    Beans
    28

    Running two commands at the same time in bash script

    Hi,

    For my work I need to create ssh tunnels to remote server and sometimes sync some files using lsyncd.

    I created a bash script with three options.
    1 => create ssh tunnel
    2 => start lsyncd
    3 => create ssh tunnel and start lsyncd

    Option 1 and 2 are working fine but option 3 it doesn't because second command run after I close the first one. How I can run both at the same time? Probably each command should run in separate konsole window? If yes, how I do that? .... if no, what are other options?

    Thanx

  2. #2
    Join Date
    Dec 2014
    Beans
    2,581

    Re: Running two commands at the same time in bash script

    You need to end the command to create a tunnel with a '&'. This tells the shell to run the command in the background and not wait for it to finish. See the section 'Lists' in the bash manual page.

    Holger

  3. #3
    Join Date
    Oct 2021
    Beans
    28

    Re: Running two commands at the same time in bash script

    ah, so simple it works, thanx

  4. #4
    Join Date
    Oct 2005
    Location
    Lab, Slovakia
    Beans
    10,791

    Re: Running two commands at the same time in bash script

    There is also more complex job control possible with the batch command, which has subcommands like bg, fg, jobs, kill etc.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •