LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   I mistakenly deleted my syslog file!! How can I ask Ubuntu to return and write to it? (https://www.linuxquestions.org/questions/linux-newbie-8/i-mistakenly-deleted-my-syslog-file-how-can-i-ask-ubuntu-to-return-and-write-to-it-4175562204/)

kobygold 12-23-2015 09:44 AM

I mistakenly deleted my syslog file!! How can I ask Ubuntu to return and write to it?
 
Hi guys,
I mistakenly deleted my 'syslog' file, from /var/log/ directory.
I wanted to clean the log from its history so I deleted the file, hoping the system will create a new one. But I noticed the system doesn't create a new one... and now I don't have the a system log anymore!!

I tried creating a blank file by the same name, but it didn't help.
I also tried copying back an older copy of the file to the same folder, but that didn't help either.

Does anyone have an idea how can I make Ubuntu return writing to the syslog in /var/log/ ?

Thanks,
Koby

Habitual 12-23-2015 09:52 AM

Ubuntu - What version/build/release/spin?

hortageno 12-23-2015 09:58 AM

[QUOTE=kobygold;5468031Does anyone have an idea how can I make Ubuntu return writing to the syslog in /var/log/ ?
[/QUOTE]

Code:

~# service rsyslog restart

kobygold 12-23-2015 11:43 AM

Thanks guys.

Habitual,
I'm using Ubuntu 14.04 LTS

hortageno,
I tried your command "~# service rsyslog restart" and got this error message:
~#: command not found

Then tried changing it slightly to "service rsyslog restart" and got those warning messages:
stop: Unknown job: rsyslog
start: Unknown job: rsyslog


Lastly I tried with sudo: "sudo service rsyslog restart" and got this messages:
rsyslog stop/waiting
rsyslog start/running, process 21920


I guess the last try is the correct one, right...?
Anyway, the syslog still doesn't change and is still empty (I created an empty file before running your command)
Am I doing something wrong...?
Do I need a restart to the Ubuntu...?
Is the directory from where I run the command important...? (I ran it from /var/log/)

Thanks,
Koby

Habitual 12-23-2015 11:57 AM

n/m.

kobygold 12-23-2015 12:57 PM

Hi Habitual,
Thanks, but can you be more specific...?
I don't understand what 'n/m' mean.

Thanks,
Koby

hortageno 12-23-2015 02:22 PM

I mistakenly deleted my syslog file!! How can I ask Ubuntu to return and write to it?
 
Remove the "~#" from the command. This was supposed to indicate that you need to run the command as root.

kobygold 12-23-2015 02:35 PM

Thanks you very much guys, it worked!!

Two more small things:
1. I noticed that I can't read the syslog as a regular user, only as a SU.
I get "permission denied" error message.
Before deleting the file I was able to read it.
Can I change that?
2. Can I clear the content of the syslog once in a while without interfering its process?
If yes, what is the command for doing that?

Thanks,
Koby

chrism01 12-23-2015 09:45 PM

Re 2; that's job for logrotate - usually specified as /etc/logrotate.conf & /etc/logrotate.d/syslog (or similar)

kobygold 12-24-2015 03:38 AM

Thanks chrism01 for your answer!
I've read a bit about the 'logrotate' command, and understood that it can be used to clean/compress/mail the log automatically daily, weekly etc.

I found another command that cleans the log upon request, which is more the usage case I need. If anyone needs it here it is:
Code:

sudo bash -c ">/var/log/syslog"

kobygold 12-24-2015 03:48 AM

Last question,
I still couldn't find a way to allow me to read the syslog without the 'sudo' command.
and I need it for some automation tools that don't have the SU permissions...

I've noticed that the file 'group' has changed from 'syslog adm' to 'syslog syslog',
and that seems to be the reason why I can't read it without the sudo.

'ls -la' shows the list below, where the first two files are accessible only using sudo, and last two are accessible regularly (without using sudo)
You can see that the last two have 'syslog adm' where the first two have 'syslog syslog'

Code:

-rw-r----- 1 syslog syslog 333974 Dec 24 11:01 syslog
-rw-r----- 1 syslog syslog 349785 Dec 24 07:55 syslog.1
-rw-r----- 1 syslog adm    682395 Dec 22 07:45 syslog.2.gz
-rw-r----- 1 syslog adm    127142 Dec 21 07:53 syslog.3.gz

Any idea how to change the groups from 'syslog syslog' to 'syslog adm'...?

Thanks,
Koby

hortageno 12-24-2015 05:48 AM

Quote:

Originally Posted by kobygold (Post 5468353)
Any idea how to change the groups from 'syslog syslog' to 'syslog adm'...?

Check /etc/rsyslog.conf. Mine has the following near the end

Code:

...
#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
...


kobygold 12-24-2015 06:14 AM

Thanks hortageno,

My rsyslog.conf file looks similar to yours (see below).
Perhaps there's a difference at the PrivDropToUser & PrivDropToGroup properties...?
Can I simply edit and change this config file...?

Code:

#
# Set the default permissions for all log files.
#
$FileOwner syslog
$FileGroup adm
$FileCreateMode 0640
$DirCreateMode 0755
$Umask 0022
$PrivDropToUser syslog
$PrivDropToGroup syslog


Habitual 12-24-2015 06:50 AM

Add yourself to adm group.
Code:

sudo useradd -G adm kobygold
Change the group on /var/log/syslog file to adm
Code:

sudo chown syslog:adm /var/log/syslog
Kobygold needs to logout and back in to take affect.

Check kobygold groups in terminal using
Code:

groups $(whoami)
cat /var/log/syslog for output.

kobygold 12-24-2015 07:13 AM

Thanks Habitual!
It worked perfectly!
You're the man! :)


All times are GMT -5. The time now is 11:22 AM.