LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Logging to a custom file (https://www.linuxquestions.org/questions/linux-newbie-8/logging-to-a-custom-file-853052/)

El_Bartos 12-29-2010 10:46 AM

Logging to a custom file
 
Hi everybody,

i have the following situation:
when you log in through the terminal as root, you get a question if you want to apply the proxyconfiguration or not. I have done this by changing the .bash_profile of the root-user:

Code:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

echo "Moeten de proxysettings worden toegepast?"
read antwoord
if [ $antwoord = "y" ]
then
    http_proxy="http://proxy....:8080"
    ftp_proxy="http://proxy....:8080"
    echo "Proxy geactiveerd."
    logger -f /var/log/proxylogger.log "Proxy set."
elif [ $antwoord = "n" ]
then
    http_proxy=""
    ftp_proxy=""
    echo "Proxy uitgeschakeld."
    logger -f /var/log/proxylogger.log "Proxy not set."
else
    echo "$antwoord is geen geldige keuze."
    logger -f /var/log/proxylogger.log "Mayday Mayday... AAAAaaaaahhh"
fi
export http_proxy ftp_proxy

In /etc/logrotation.d/ directory, I have made a file called "proxylogger" with the following code inside:

Code:

/var/log/proxylogger.log {
    daily
    missingok
    notifempty
    rotate 10
    compress
}

I have adapted rsyslog with the following:

Code:

# Opslaan van berichten i.v.m. de proxyinstellingen bij het inloggen als root.
local5.*                        /var/log/proxylogger.log

But it doesn't work. The messages have to be written to the logfile by using the logger-command.
What am I doing wrong?

I'm only into Linux for a few weeks (following a course)

unSpawn 12-29-2010 11:39 AM

If you defined the LOCAL5 facility (and restarted rsyslogd) then shouldn't you be using 'logger -p local5.info "message";' instead of "-f"?

El_Bartos 12-30-2010 06:32 AM

Quote:

Originally Posted by unSpawn (Post 4206807)
If you defined the LOCAL5 facility (and restarted rsyslogd) then shouldn't you be using 'logger -p local5.info "message";' instead of "-f"?

It worked! Thank you :D
I've been searching 3 days for this but I just couldn't find the solution. And now that I see it, it seems so easy and logic to.
The problem was that I didn't knew how to use the facility in a correct way together with the logger-command.

unSpawn, you just made my day :cool:

unSpawn 12-30-2010 10:11 AM

Quote:

Originally Posted by El_Bartos (Post 4207644)
you just made my day

If that makes your day then I'd say be very careful. Since you've only used Linux for a few weeks now any more exhilaration might get you hooked on the stuff :-] Before we know it' you'll be coding like a $deity...

While Linux has a somewhat undeserved reputation for its terse and cryptic manuals they do provide you with a lot of nfo as long as you're willing to read (and read and read) and know how and where to find it (as in: 'which logger', 'whatis logger', 'locate logger', 'apropos logger', 'grep -r /usr/share/doc -ie n/logger', 'man logger' or search LQ). Your distribution (do fill in your details in your LQ user control panel) might provide basic information and then there's generic tutorials abound like Rute you might find interesting. Same goes for scripting: search LQ and you'll find a cornucopia of scripts (or see Heiner's SHELLdorado).


BTW, I forgot to mention that wrt the original topic: it's customary to treat the root account as a non-human account only for admin purposes. As such, I mean if you don't have any compelling reasons for requiring proxy variables to be set this way, you best leave the root shell environment as "clean" as possible. If you do change things do make backups so you have something to revert back to in case of a SNAFU.


All times are GMT -5. The time now is 11:19 PM.