-1

I'm running an embedded Linux (Dreadnaught), and I'd like to be able to manually enter a line into the syslog as the user login, and have the result of other commands stored in the syslog. e.g.:

echo ======== Setting chat and Options for Insys >>/var/log/messages
cat /etc/ppp/options >> /var/log/messages

Syslog is initiated in /etc/inittab:

::respawn:/sbin/syslogd -n -s 200 -b 2 -S -m0

I have some alias' to perform common tasks, and I'd like syslog to be updated when they are run:

alias Insys='echo =================== Setting chat and Options for Insys >> /var/log/messages; cp /var/config/tw_con_Insys.lge /var/config/tw_con.lge; cp /etc/ppp/peers/tw_options_Insys /etc/ppp/peers/tw_options; con; echo =================== Complete >> /var/log/messages'
alias setup='echo =================== options ===================; echo ""; echo ""; cat /etc/ppp/options; echo ""; echo ""; echo =================== chat ===================; echo ""; echo ""; cat /var/config/tw_con.lge; echo ""; echo ============================================;'

The setup command writes to the terminal, I would like it to write to the syslog instead, i.e. setup>>/var/log/messages.

The problem is that /var/log/messages is owned by root, not user. I can manually run

 su -c 'chmod 777 /var/log/messages'

, it prompts me for the root pwd, then after this I can run my shortcuts and they work. However, each time the log rolls over to messages.0 and a new messages is created, I've lost the privs and have to run it again.

I tried to create an alias for this chmod so I can run it before I run my custom scripts:

alias userlog='su -c ''chmod 777 /var/log/messages'''

The alias is accepted, but doesn't run.

[user@Dreadnaught_TEP1 etc]$ userlog
su: unknown user 777

Thanks for your help!

  • Don't use >> to append to the file, use the actual syslog command. man syslog should tell you more. – Panki Sep 11 at 14:05
  • There isn't a syslog command in this build, and syslogd doesn't appear to let me use it as a conduit:`[user@Dreadnaught_TEP1 /sbin]$ echo "============test" |syslogd' did nothing. – Scott Sep 11 at 14:44
  • ' [user@Dreadnaught_TEP1 /sbin]$ syslogd -? syslogd: invalid option -- '?' BusyBox v1.17.1 (2018-03-05 11:01:55 AEST) multi-call binary. Usage: syslogd [OPTIONS] System logging utility. This version of syslogd ignores /etc/syslog.conf ' – Scott Sep 11 at 14:45
  • 'Options: -n Run in foreground -O FILE Log to given file (default:/var/log/messages) -l N Set local log level -S Smaller logging output -s SIZE Max size (KB) before rotate (default:200KB, 0=off) -b N N rotated logs to keep (default:1, max=99, 0=purge) -R HOST[:PORT] Log to IP or hostname on PORT (default PORT=514/UDP) -L Log locally and via network (default is network only if -R) -D Drop duplicates – Scott Sep 11 at 14:45
  • 1
    I'm not sure what to do about your alias command, since it appears to have an odd number of single quotes. But it might be better to use the logger command. – Mark Plotnick Sep 11 at 21:56
0

Solved thanks to @MarkPlotnick! the logger command does what I need, no need for chmod or anything like that.

alias Insys='logger =================== Setting chat and Options for Insys ;      cp /var/config/tw_con_Insys.lge /var/config/tw_con.lge;     cp /etc/ppp/peers/tw_options_Insys /etc/ppp/peers/tw_options;     con; logger =================== Complete; setup '
alias setup='logger =================== options ===================; cat /etc/ppp/options | logger; logger =================== chat ===================;  cat /var/config/tw_con.lge | logger; logger ============================================'

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.