Log /etc/rc.local std{out,err} #66

Closed
opened 2025-02-18 14:16:42 +01:00 by Benjamin_Loison · 26 comments
(echo my_stdout_content && echo my_stderr_content >&2)
Output:
my_stdout_content
my_stderr_content
(echo my_stdout_content && echo my_stderr_content >&2) > /dev/null
my_stderr_content
(echo my_stdout_content && echo my_stderr_content >&2) 2> /dev/null
my_stdout_content

Would help Benjamin_Loison/openssh/issues/20.

```bash (echo my_stdout_content && echo my_stderr_content >&2) ``` <details> <summary>Output:</summary> ``` my_stdout_content my_stderr_content ``` </details> ```bash (echo my_stdout_content && echo my_stderr_content >&2) > /dev/null ``` ``` my_stderr_content ``` ```bash (echo my_stdout_content && echo my_stderr_content >&2) 2> /dev/null ``` ``` my_stdout_content ``` Would help [Benjamin_Loison/openssh/issues/20](https://salsa.debian.org/Benjamin_Loison/openssh/-/issues/20).
Author
Owner
/etc/rc.local:
#!/bin/sh

(echo my_stdout_content && echo my_stderr_content >&2)
<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh (echo my_stdout_content && echo my_stderr_content >&2) ``` </details>
Author
Owner
sudo find / -name 'my_stdout.txt' 2> /dev/null

does not return anything on reboot.

```bash sudo find / -name 'my_stdout.txt' 2> /dev/null ``` does not return anything on reboot.
Author
Owner
Let us add:
while [ true ]
do
    sleep 1
done

to see if boot stays stuck as & usage seems to suggest.

Benjamin_Loison/coreutils/issues/19 would help.

<details> <summary>Let us add:</summary> ```bash while [ true ] do sleep 1 done ``` </details> to see if boot stays stuck as `&` usage seems to suggest. [Benjamin_Loison/coreutils/issues/19](https://codeberg.org/Benjamin_Loison/coreutils/issues/19) would help.
Author
Owner

Well it is not, so maybe the permissions are to blame.

ls -l /etc/rc.local
-rwxr-xr-x 1 root root XXX XXX.  XX XX:XX /etc/rc.local

is expected.

Well it is not, so maybe the permissions are to blame. ```bash ls -l /etc/rc.local ``` ``` -rwxr-xr-x 1 root root XXX XXX. XX XX:XX /etc/rc.local ``` is expected.
Author
Owner

I have:

ls -l /etc/rc.local
-rw-r--r-- 1 root root 134 Feb 18 14:22 /etc/rc.local
I have: ```bash ls -l /etc/rc.local ``` ``` -rw-r--r-- 1 root root 134 Feb 18 14:22 /etc/rc.local ```
Author
Owner
sudo chmod +x /etc/rc.local
ls -l /etc/rc.local
-rwxr-xr-x 1 root root 134 Feb 18 14:22 /etc/rc.local
```bash sudo chmod +x /etc/rc.local ls -l /etc/rc.local ``` ``` -rwxr-xr-x 1 root root 134 Feb 18 14:22 /etc/rc.local ```
Author
Owner
sudo find / -name 'my_stdout.txt' 2> /dev/null
/my_stdout.txt
```bash sudo find / -name 'my_stdout.txt' 2> /dev/null ``` ``` /my_stdout.txt ```
Author
Owner
mktemp --suffix _etc_rc_local_stdout
/tmp/tmp.hdUio8goPt_etc_rc_local_stdout

However, permanent with date logs would be nice.

echo "Start of /etc/rc.local at `date`"

may help.

```bash mktemp --suffix _etc_rc_local_stdout ``` ``` /tmp/tmp.hdUio8goPt_etc_rc_local_stdout ``` However, permanent with date logs would be nice. ```bash echo "Start of /etc/rc.local at `date`" ``` may help.
Author
Owner
ls /etc/
Output:
adduser.conf		cups		     group	      libpaper.d      NetworkManager  rc5.d		 sudoers.d
adjtime			cupshelpers	     group-	      libreoffice     networks	      rc6.d		 sudo_logsrvd.conf
aliases			dbus-1		     grub.d	      lighttpd	      nftables.conf   rc.local		 sv
alsa			dconf		     gshadow	      locale.alias    nsswitch.conf   rcS.d		 sysctl.conf
alternatives		debconf.conf	     gshadow-	      locale.gen      openal	      request-key.conf	 sysctl.d
anacrontab		debian_version	     gss	      localtime       openni2	      resolv.conf	 sysstat
anthy			default		     gtk-2.0	      logcheck	      opt	      rmt		 systemd
apache2			deluser.conf	     gtk-3.0	      login.defs      os-release      rpc		 terminfo
apg.conf		dhcp		     hdparm.conf      logrotate.conf  PackageKit      runit		 thunderbird
apparmor		dictionaries-common  host.conf	      logrotate.d     pam.conf	      rygel.conf	 timezone
apparmor.d		dkms		     hostname	      lvm	      pam.d	      sane.d		 timidity
appstream.conf		dpkg		     hosts	      lynx	      papersize       security		 tmispell.conf
apt			e2scrub.conf	     hosts.allow      machine-id      passwd	      selinux		 tmpfiles.d
avahi			emacs		     hosts.deny       magic	      passwd-	      sensors3.conf	 ucf.conf
bash.bashrc		email-addresses      ifplugd	      magic.mime      pcmcia	      sensors.d		 udev
bindresvport.blacklist	environment	     ImageMagick-6    mailcap	      perl	      services		 udisks2
binfmt.d		environment.d	     init.d	      mailcap.order   pki	      sgml		 ufw
bluetooth		ethertypes	     initramfs-tools  mailname	      plymouth	      shadow		 update-motd.d
bogofilter.cf		exim4		     inputrc	      mail.rc	      polkit-1	      shadow-		 UPower
ca-certificates		firefox-esr	     insserv.conf.d   manpath.config  ppp	      shells		 usb_modeswitch.conf
ca-certificates.conf	fonts		     ipp-usb	      mdadm	      presage.xml     skel		 usb_modeswitch.d
chatscripts		fstab		     iproute2	      mime.types      profile	      smartd.conf	 vdpau_wrapper.cfg
chromium		fuse.conf	     issue	      mke2fs.conf     profile.d       smartmontools	 vim
console-setup		fwupd		     issue.net	      mlterm	      protocols       snmp		 vulkan
cracklib		gai.conf	     kernel	      ModemManager    pulse	      speech-dispatcher  wpa_supplicant
cron.d			gdm3		     ldap	      modprobe.d      python3	      ssh		 X11
cron.daily		geoclue		     ld.so.cache      modules	      python3.11      ssl		 xattr.conf
cron.hourly		ghostscript	     ld.so.conf       modules-load.d  qemu	      subgid		 xdg
cron.monthly		glvnd		     ld.so.conf.d     motd	      rc0.d	      subgid-		 xml
crontab			gnome		     libao.conf       mtab	      rc1.d	      subuid		 zhcon.conf
cron.weekly		gnome-chess	     libaudit.conf    nanorc	      rc2.d	      subuid-
cron.yearly		gprofng.rc	     libblockdev      netconfig       rc3.d	      sudo.conf
crypttab		groff		     libnl-3	      network	      rc4.d	      sudoers

so this folder looks already quite full.

```bash ls /etc/ ``` <details> <summary>Output:</summary> ``` adduser.conf cups group libpaper.d NetworkManager rc5.d sudoers.d adjtime cupshelpers group- libreoffice networks rc6.d sudo_logsrvd.conf aliases dbus-1 grub.d lighttpd nftables.conf rc.local sv alsa dconf gshadow locale.alias nsswitch.conf rcS.d sysctl.conf alternatives debconf.conf gshadow- locale.gen openal request-key.conf sysctl.d anacrontab debian_version gss localtime openni2 resolv.conf sysstat anthy default gtk-2.0 logcheck opt rmt systemd apache2 deluser.conf gtk-3.0 login.defs os-release rpc terminfo apg.conf dhcp hdparm.conf logrotate.conf PackageKit runit thunderbird apparmor dictionaries-common host.conf logrotate.d pam.conf rygel.conf timezone apparmor.d dkms hostname lvm pam.d sane.d timidity appstream.conf dpkg hosts lynx papersize security tmispell.conf apt e2scrub.conf hosts.allow machine-id passwd selinux tmpfiles.d avahi emacs hosts.deny magic passwd- sensors3.conf ucf.conf bash.bashrc email-addresses ifplugd magic.mime pcmcia sensors.d udev bindresvport.blacklist environment ImageMagick-6 mailcap perl services udisks2 binfmt.d environment.d init.d mailcap.order pki sgml ufw bluetooth ethertypes initramfs-tools mailname plymouth shadow update-motd.d bogofilter.cf exim4 inputrc mail.rc polkit-1 shadow- UPower ca-certificates firefox-esr insserv.conf.d manpath.config ppp shells usb_modeswitch.conf ca-certificates.conf fonts ipp-usb mdadm presage.xml skel usb_modeswitch.d chatscripts fstab iproute2 mime.types profile smartd.conf vdpau_wrapper.cfg chromium fuse.conf issue mke2fs.conf profile.d smartmontools vim console-setup fwupd issue.net mlterm protocols snmp vulkan cracklib gai.conf kernel ModemManager pulse speech-dispatcher wpa_supplicant cron.d gdm3 ldap modprobe.d python3 ssh X11 cron.daily geoclue ld.so.cache modules python3.11 ssl xattr.conf cron.hourly ghostscript ld.so.conf modules-load.d qemu subgid xdg cron.monthly glvnd ld.so.conf.d motd rc0.d subgid- xml crontab gnome libao.conf mtab rc1.d subuid zhcon.conf cron.weekly gnome-chess libaudit.conf nanorc rc2.d subuid- cron.yearly gprofng.rc libblockdev netconfig rc3.d sudo.conf crypttab groff libnl-3 network rc4.d sudoers ``` </details> so this folder looks already quite full.
Author
Owner
cd /root/

works as wanted.

```bash cd /root/ ``` works as wanted.
Author
Owner
/etc/rc.local:
#!/bin/sh

FOLDER_NAME=etc_rc_local
su --login benjamin_loison -c "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/

    log() {
        # Should ensure that date is not evaluated at script reading
        echo `date` \"$@\"
    }

    (
        log Start
        (
            echo my_stdout_content
            echo my_stderr_content >&2
        )
        log End
    ) >> stdout.txt 2>> stderr.txt
"
cat etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025
my_stdout_content
End of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025
my_stderr_content

After a reboot:

cat etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025
my_stdout_content
End of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025
Start of /etc/rc.local at Tue Feb 18 02:59:50 PM CET 2025
my_stdout_content
End of /etc/rc.local at Tue Feb 18 02:59:50 PM CET 2025
my_stderr_content
my_stderr_content
<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh FOLDER_NAME=etc_rc_local su --login benjamin_loison -c " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ log() { # Should ensure that date is not evaluated at script reading echo `date` \"$@\" } ( log Start ( echo my_stdout_content echo my_stderr_content >&2 ) log End ) >> stdout.txt 2>> stderr.txt " ``` </details> ```bash cat etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025 my_stdout_content End of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025 my_stderr_content ``` </details> After a reboot: ```bash cat etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025 my_stdout_content End of /etc/rc.local at Tue Feb 18 02:56:46 PM CET 2025 Start of /etc/rc.local at Tue Feb 18 02:59:50 PM CET 2025 my_stdout_content End of /etc/rc.local at Tue Feb 18 02:59:50 PM CET 2025 my_stderr_content my_stderr_content ``` </details>
Author
Owner

while [ true ] makes the boot stuck.

`while [ true ]` makes the boot stuck.
Author
Owner
Shell:
while [ true ]
do
    echo hey
    sleep 1
done &
[1] 95150
benjamin_loison@Benjamin-Loison-HP-Debian:~$ hey
hey
hey
hey
^C
benjamin_loison@Benjamin-Loison-HP-Debian:~$ hey
hey
hey
<details> <summary>Shell:</summary> ``` while [ true ] do echo hey sleep 1 done & [1] 95150 benjamin_loison@Benjamin-Loison-HP-Debian:~$ hey hey hey hey ^C benjamin_loison@Benjamin-Loison-HP-Debian:~$ hey hey hey ``` </details>
Author
Owner
Shell:
while [ true ]
do
    echo hey
    sleep 1
done >> log.txt &
[1] 95309

log.txt correctly get filled.

<details> <summary>Shell:</summary> ``` while [ true ] do echo hey sleep 1 done >> log.txt & [1] 95309 ``` </details> `log.txt` correctly get filled.
Author
Owner
/etc/rc.local:
#!/bin/sh

SCRIPT='/etc/rc.local'
FOLDER_NAME=etc_rc_local
su --login benjamin_loison -c "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/
    (
        echo \"Start of $SCRIPT at `date`\"
        (
            while [ true ]
            do
                date
                echo my_stdout_content
                echo my_stderr_content >&2
                sleep 1
            done
        )
        echo \"End of $SCRIPT at `date`\"
    ) >> stdout.txt 2>> stderr.txt &
"
head -n 5 etc_rc_local/std{out,err}.txt
Output:
==> etc_rc_local/stdout.txt <==
Start of /etc/rc.local at Tue Feb 18 03:38:16 PM CET 2025
Tue Feb 18 03:38:17 PM CET 2025
my_stdout_content
Tue Feb 18 03:38:18 PM CET 2025
my_stdout_content

==> etc_rc_local/stderr.txt <==
my_stderr_content
my_stderr_content
my_stderr_content
my_stderr_content
my_stderr_content
<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh SCRIPT='/etc/rc.local' FOLDER_NAME=etc_rc_local su --login benjamin_loison -c " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ ( echo \"Start of $SCRIPT at `date`\" ( while [ true ] do date echo my_stdout_content echo my_stderr_content >&2 sleep 1 done ) echo \"End of $SCRIPT at `date`\" ) >> stdout.txt 2>> stderr.txt & " ``` </details> ```bash head -n 5 etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` ==> etc_rc_local/stdout.txt <== Start of /etc/rc.local at Tue Feb 18 03:38:16 PM CET 2025 Tue Feb 18 03:38:17 PM CET 2025 my_stdout_content Tue Feb 18 03:38:18 PM CET 2025 my_stdout_content ==> etc_rc_local/stderr.txt <== my_stderr_content my_stderr_content my_stderr_content my_stderr_content my_stderr_content ``` </details>
Author
Owner
/etc/rc.local:
#!/bin/sh

SCRIPT='/etc/rc.local'
FOLDER_NAME=etc_rc_local
su --login benjamin_loison -c "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/
    (
        echo \"Start of $SCRIPT at `date`\"
        autossh CENSORED_VPS -NR 2224:localhost:22
        echo \"End of $SCRIPT at `date`\"
    ) >> stdout.txt 2>> stderr.txt &
"
cat etc_rc_local/std{out,err}.txt
Start of /etc/rc.local at Tue Feb 18 03:44:42 PM CET 2025

After a reboot:

cat etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 03:44:42 PM CET 2025
Start of /etc/rc.local at Tue Feb 18 03:45:39 PM CET 2025
<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh SCRIPT='/etc/rc.local' FOLDER_NAME=etc_rc_local su --login benjamin_loison -c " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ ( echo \"Start of $SCRIPT at `date`\" autossh CENSORED_VPS -NR 2224:localhost:22 echo \"End of $SCRIPT at `date`\" ) >> stdout.txt 2>> stderr.txt & " ``` </details> ```bash cat etc_rc_local/std{out,err}.txt ``` ``` Start of /etc/rc.local at Tue Feb 18 03:44:42 PM CET 2025 ``` After a reboot: ```bash cat etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 03:44:42 PM CET 2025 Start of /etc/rc.local at Tue Feb 18 03:45:39 PM CET 2025 ``` </details>
Author
Owner

Tested on Debian 12 GNOME.

Tested on Debian 12 GNOME.
Author
Owner
/etc/rc.local:
#!/bin/sh

SCRIPT='/etc/rc.local'
FOLDER_NAME=etc_rc_local
su --login benjamin_loison -c "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/
    (
        echo \"Start of $SCRIPT at `date`\" | tee /dev/stderr
		autossh CENSORED_VPS -NR 2224:localhost:22
        echo \"End of $SCRIPT at `date`\" | tee /dev/stderr
    ) >> stdout.txt 2>> stderr.txt &
"

Source: the Stack Overflow answer 6852984

cat etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 04:09:41 PM CET 2025
Start of /etc/rc.local at Tue Feb 18 04:09:41 PM CET 2025

would help figure out when an error occurs.

<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh SCRIPT='/etc/rc.local' FOLDER_NAME=etc_rc_local su --login benjamin_loison -c " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ ( echo \"Start of $SCRIPT at `date`\" | tee /dev/stderr autossh CENSORED_VPS -NR 2224:localhost:22 echo \"End of $SCRIPT at `date`\" | tee /dev/stderr ) >> stdout.txt 2>> stderr.txt & " ``` </details> Source: [the Stack Overflow answer 6852984](https://stackoverflow.com/a/6852984) ```bash cat etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 04:09:41 PM CET 2025 Start of /etc/rc.local at Tue Feb 18 04:09:41 PM CET 2025 ``` </details> would help figure out when an error occurs.
Author
Owner

Let us not add tail -c +2 to be precise, despite being less clean in this case.

Let us not add `tail -c +2` to be precise, despite being less clean in this case.
Author
Owner
Source: [the Stack Overflow question 51877092](https://stackoverflow.com/q/51877092).
Author
Owner

Without autossh:

cat _etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025
End of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025
End of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025

If add -a to tee:

cat _etc_rc_local/std{out,err}.txt
Output:
Start of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025
End of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025
Start of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025
End of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025
Without `autossh`: ```bash cat _etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025 End of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025 End of /etc/rc.local at Tue Feb 18 04:24:02 PM CET 2025 ``` </details> If add `-a` to `tee`: ```bash cat _etc_rc_local/std{out,err}.txt ``` <details> <summary>Output:</summary> ``` Start of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025 End of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025 Start of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025 End of /etc/rc.local at Tue Feb 18 04:31:11 PM CET 2025 ``` </details>
Author
Owner
/etc/rc.local:
#!/bin/sh

USER_NAME=benjamin_loison
SERVER_HOST_NAME=CENSORED_VPS
SERVER_PORT=2224

SCRIPT="$0"
FOLDER_NAME=`echo -n "$SCRIPT" | tr -c 'a-z' _`

export AUTOSSH_FIRST_POLL=30

su --login $USER_NAME -c "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/
    (
        echo \"Start of $SCRIPT at `date`\" | tee -a /dev/stderr
        env
        echo \"|$AUTOSSH_FIRST_POLL|\"
        autossh $SERVER_HOST_NAME -NR $SERVER_PORT:localhost:22
        echo \"End of $SCRIPT at `date`\" | tee -a /dev/stderr
    ) >> stdout.txt 2>> stderr.txt &
"
results in:
SHELL=/bin/bash
LANGUAGE=en_US:en
PWD=/home/benjamin_loison/_etc_rc_local
LOGNAME=benjamin_loison
XDG_SESSION_TYPE=unspecified
HOME=/home/benjamin_loison
LANG=en_US.UTF-8
XDG_SESSION_CLASS=background
TERM=linux
USER=benjamin_loison
SHLVL=1
XDG_SESSION_ID=c1
XDG_RUNTIME_DIR=/run/user/1000
XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/
PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
MAIL=/var/mail/benjamin_loison
_=/usr/bin/env
OLDPWD=/home/benjamin_loison
|30|

So env does not mention it but AUTOSSH_FIRST_POLL is correctly set within -c.

<details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh USER_NAME=benjamin_loison SERVER_HOST_NAME=CENSORED_VPS SERVER_PORT=2224 SCRIPT="$0" FOLDER_NAME=`echo -n "$SCRIPT" | tr -c 'a-z' _` export AUTOSSH_FIRST_POLL=30 su --login $USER_NAME -c " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ ( echo \"Start of $SCRIPT at `date`\" | tee -a /dev/stderr env echo \"|$AUTOSSH_FIRST_POLL|\" autossh $SERVER_HOST_NAME -NR $SERVER_PORT:localhost:22 echo \"End of $SCRIPT at `date`\" | tee -a /dev/stderr ) >> stdout.txt 2>> stderr.txt & " ``` </details> <details> <summary>results in:</summary> ``` SHELL=/bin/bash LANGUAGE=en_US:en PWD=/home/benjamin_loison/_etc_rc_local LOGNAME=benjamin_loison XDG_SESSION_TYPE=unspecified HOME=/home/benjamin_loison LANG=en_US.UTF-8 XDG_SESSION_CLASS=background TERM=linux USER=benjamin_loison SHLVL=1 XDG_SESSION_ID=c1 XDG_RUNTIME_DIR=/run/user/1000 XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/ PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus MAIL=/var/mail/benjamin_loison _=/usr/bin/env OLDPWD=/home/benjamin_loison |30| ``` </details> So `env` does not mention it but `AUTOSSH_FIRST_POLL` is correctly set within `-c`.
Author
Owner

There is no need to wait 30 seconds after boot in my Virtual Machine Manager virtual machine to access it via SSH:

autossh --help 2>&1 | grep AUTOSSH_FIRST_POLL
    AUTOSSH_FIRST_POLL  - time before first connection check (seconds)
man autossh
Output:
...
     AUTOSSH_FIRST_POLL
             Specifies the time to wait before the first connection test. Thereafter the general poll time is used (see AUTOSSH_POLL below).
...
     AUTOSSH_POLL
             Specifies the connection poll time in seconds; default is 600 seconds.  Unless AUTOSSH_FIRST_POLL is used, the first poll time
             will set to match the poll time. If the poll time is less than twice the network timeouts (default 15 seconds) the network time‐
             outs will be adjusted downward to 1/2 the poll time.
...

these are the only references to AUTOSSH_FIRST_POLL and AUTOSSH_POLL.

So 30 seconds seems to just be make 600 seconds behavior happens faster.

There is no need to wait 30 seconds after boot in my Virtual Machine Manager virtual machine to access it via SSH: ```bash autossh --help 2>&1 | grep AUTOSSH_FIRST_POLL ``` ``` AUTOSSH_FIRST_POLL - time before first connection check (seconds) ``` ```bash man autossh ``` <details> <summary>Output:</summary> ``` ... AUTOSSH_FIRST_POLL Specifies the time to wait before the first connection test. Thereafter the general poll time is used (see AUTOSSH_POLL below). ... AUTOSSH_POLL Specifies the connection poll time in seconds; default is 600 seconds. Unless AUTOSSH_FIRST_POLL is used, the first poll time will set to match the poll time. If the poll time is less than twice the network timeouts (default 15 seconds) the network time‐ outs will be adjusted downward to 1/2 the poll time. ... ``` </details> these are the only references to `AUTOSSH_FIRST_POLL` and `AUTOSSH_POLL`. So 30 seconds seems to just be make 600 seconds behavior happens faster.
Author
Owner

I tested on my host Debian 12 GNOME laptop flat wifi:

/etc/rc.local:
#!/bin/sh

LOCAL_USER_NAME=benjamin_loison
SERVER_HOST_NAME=CENSORED_VPS
SERVER_PORT=2224

SCRIPT="$0"
FOLDER_NAME=`echo -n "$SCRIPT" | tr -c 'a-z' _`

export AUTOSSH_FIRST_POLL=30

su --login $LOCAL_USER_NAME --command "
    mkdir $FOLDER_NAME/
    cd $FOLDER_NAME/
    (
        echo \"Start of $SCRIPT at `date`\" | tee -a /dev/stderr
        autossh $SERVER_HOST_NAME -NR $SERVER_PORT:localhost:22
        echo \"End of $SCRIPT at `date`\" | tee -a /dev/stderr
    ) >> stdout.txt 2>> stderr.txt &
"

and it works fine without waiting 30 seconds.

I tested on my host Debian 12 GNOME laptop flat wifi: <details> <summary><code>/etc/rc.local</code>:</summary> ```bash #!/bin/sh LOCAL_USER_NAME=benjamin_loison SERVER_HOST_NAME=CENSORED_VPS SERVER_PORT=2224 SCRIPT="$0" FOLDER_NAME=`echo -n "$SCRIPT" | tr -c 'a-z' _` export AUTOSSH_FIRST_POLL=30 su --login $LOCAL_USER_NAME --command " mkdir $FOLDER_NAME/ cd $FOLDER_NAME/ ( echo \"Start of $SCRIPT at `date`\" | tee -a /dev/stderr autossh $SERVER_HOST_NAME -NR $SERVER_PORT:localhost:22 echo \"End of $SCRIPT at `date`\" | tee -a /dev/stderr ) >> stdout.txt 2>> stderr.txt & " ``` </details> and it works fine without waiting 30 seconds.
Author
Owner
Bash script:
sudo su --login benjamin_loison -c "
    log() {
        # Should ensure that date is not evaluated at script reading
        echo `date` \"$@\"
    }

    log test
"
Sat 22 Feb 10:42:01 CET 2025
<details> <summary>Bash script:</summary> ```bash sudo su --login benjamin_loison -c " log() { # Should ensure that date is not evaluated at script reading echo `date` \"$@\" } log test " ``` </details> ``` Sat 22 Feb 10:42:01 CET 2025 ```
Author
Owner
Bash script:
log() {
    # Should ensure that date is not evaluated at script reading
    echo `date` \"$@\"
}

log hey

sudo su --login benjamin_loison -c "
    log test
"
Sat 22 Feb 10:47:30 CET 2025 "hey"
-bash: line 2: log: command not found

Maybe export may help as it may help with AUTOSSH_FIRST_POLL.

See Benjamin_Loison/util-linux/issues/7.

<details> <summary>Bash script:</summary> ```bash log() { # Should ensure that date is not evaluated at script reading echo `date` \"$@\" } log hey sudo su --login benjamin_loison -c " log test " ``` </details> ``` Sat 22 Feb 10:47:30 CET 2025 "hey" -bash: line 2: log: command not found ``` Maybe `export` may help as it may help with `AUTOSSH_FIRST_POLL`. See [Benjamin_Loison/util-linux/issues/7](https://codeberg.org/Benjamin_Loison/util-linux/issues/7).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Benjamin_Loison/linux#66
No description provided.