Results 1 to 5 of 5

Thread: Cron job, how to? Automate "socat"

  1. #1

    Default Cron job, how to? Automate "socat"

    Hi Everybody!

    I want to automate some of my tasks. I need to keep "socat" connection to another host. Command are the following:
    Code:
    socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.0.100:7001
    If everything is ok, socat will start to forward all data from remote host to /dev/ttyS0, until it will closed. But some times socat can't start correctly and need to be restarted. How I can made it?

    Sorry for my English )
    Thanks in advance.

  2. #2
    Join Date
    Nov 2008
    Location
    N. Wales
    Posts
    1,028

    Default Re: Cron job, how to? Automate "socat"

    ToLive adjusted his/her AFDB on Saturday 15 Aug 2009 07:16 to write:

    >
    > Hi Everybody!
    >
    > I want to automate some of my tasks. I need to keep "socat" connection
    > to another host. Command are the following:
    >
    > Code:
    > --------------------
    > socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.0.100:7001
    > --------------------
    >
    > If everything is ok, socat will start to forward all data from remote
    > host to /dev/ttyS0, until it will closed. But some times socat can't
    > start correctly and need to be restarted. How I can made it?


    Do you want this to start on machine start-up or will just cron do?

    If start-up sounds better then have a look in /etc/init.d/skeleton here is a
    preformed template for a script that can be used as a base for such things.

    Otherwise you can have a cron script as root or user.

    I would attempt to do it myself but my scripting is not elegant/pretty I
    would suggest you ask in the scripting group here, there are some wizz kids
    in there which will probably give you a quick one liner that would do what
    would take me reams of code :-)


    HTH

    --
    Mark
    Caveat emptor
    Nullus in verba
    Nil illegitimi carborundum

  3. #3
    Join Date
    Mar 2008
    Location
    Oz
    Posts
    11,728
    Blog Entries
    2

    Default Re: Cron job, how to? Automate "socat"

    You can add that command into a cron table: reference here:
    Cron Tables (Crontab) in Suse / openSUSE [Event Scheduler for 10.x, 11.x]

    But the difficult thing would be if it fails to start. For that you need an extended script. You set the cron job to trigger at a prearranged time and run the script. The script would run the command then sleep x seconds then test if the transfer is running then if no then run the command again but if yes then end. Or like that.

    Have a look at bash scripting or more advanced, like perl.
    Leap 42.3 & 15.1 &KDE
    FYIs from the days of yore

  4. #4
    Join Date
    Jun 2008
    Location
    UTC+10
    Posts
    9,686
    Blog Entries
    4

    Default Re: Cron job, how to? Automate "socat"

    If it can be regarded as a system service you can also add it to /etc/inittab. Add a line like this:

    Code:
    SO:35:respawn:socat PTY,link=/dev/ttyS0,raw,echo=0 tcp4:192.168.0.100:7001
    then kick init to reread inittab by doing as root

    Code:
    init q
    It will be run when entering either runlevel 3 or runlevel 5 and if it terminates, another instance will be started.

    However this might not work if networking is not up at the time the runlevel is entered and then it would try to respawn too many times and then init will disable it for a while.

  5. #5

    Default Re: Cron job, how to? Automate "socat"

    Big thanks! I will try it all on monday.

Posting Permissions

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