MonthJuly 2012

replace newline with sed

update: I recommend this solution now.

Several times needed and always forgotten how it works: Replace newline on the shell with sed. So I decided to write it down here, that at least I know where to look for…

Example, convert this:


into this:


cat the file and pipe it through sed like so:

cat newlinefile | sed -n '1h;2,$H;${g;s/\n/;/g;p}'

happy substituting!

send an e-mail when user logs in

When administrators get paranoid, they sometimes want to know every login on one of their linux boxes. If you are the only user of this box, you immediately know when something’s wrong. The trick is simple – place that (and substitute your e-mail address) into /etc/bash.bashrc:

#mail login infos...
echo -e "Hi\n\nuser $USER logged in at $(date).\n\nhope thats okay... \
\n\nregards, bash" | mail your@email.address -s \
"$USER logged in to $(hostname).$(dnsdomainname)" -a "From: loginwatcher"

From now on you will get an e-mail every time a user opens a bash.

You can test your mail settings with:

echo "test" | mail your@email.address -s test

If it doesn’t work, you have to check your mail settings.. on debian systems, it may help to do the configuration of exim once again:

dpkg-reconfigure exim4-config

hope that helps :)

© 2017 netmess

Theme by Anders NorenUp ↑