GNU/Linux

From WhyNotWiki
Jump to: navigation, search

GNU/Linux  edit   (Category  edit) .


This is for miscellaneous GNU/Linux tips, including how to use miscellaneous commands that don't require their own sections.

Contents

Log files

ONLamp.com -- Where the Log Files Live

> apropos syslog
/usr/sbin/lm-syslog-setup (8) [lm-syslog-setup] - configure laptop mode to switch syslog.conf based on power state
eximstats (8)        - generates statistics from Exim mainlog or syslog files.
lm-syslog-setup (8)  - configure laptop mode to switch syslog.conf based on power state
logger (1)           - a shell command interface to the syslog(3) system log module
syslog-facility (8)  - Setup and remove LOCALx facility for sysklogd
syslog.conf (5)      - syslogd(8) configuration file
syslog2eximlog (8)   - make syslog output suitable for eximstats
syslogd (8)          - Linux system logging utilities.
syslogd-listfiles (8) - list system logfiles

dmesg: Can I see the "dmesg" log for previous days?

Yes. Although /var/log/dmesg only holds the results for the most recent boot sequence, a copy of that appears to also be logged to /var/log/syslog, which hangs around longer (is not overwritten with every new boot but simply appended to).

Why is it only keeping 7 days worth of logs?

> ll /var/log/syslog*
-rw-r----- 1 syslog adm 158169 2008-05-07 19:17 /var/log/syslog
-rw-r----- 1 syslog adm 172926 2008-05-07 07:39 /var/log/syslog.0
-rw-r----- 1 syslog adm   3955 2008-05-06 08:39 /var/log/syslog.1.gz
-rw-r----- 1 syslog adm   3494 2008-05-05 07:39 /var/log/syslog.2.gz
-rw-r----- 1 syslog adm   3464 2008-05-04 07:39 /var/log/syslog.3.gz
-rw-r----- 1 syslog adm   3891 2008-05-03 07:39 /var/log/syslog.4.gz
-rw-r----- 1 syslog adm  19350 2008-05-02 07:39 /var/log/syslog.5.gz
-rw-r----- 1 syslog adm   5550 2008-05-01 07:39 /var/log/syslog.6.gz

I want it to keep my log files forever (until I choose to manually delete them). How do I change that?

/etc/logrotate.conf doesn't appear to be what's controlling it, because there I see several settings which are different from what I am seeing in /var/log/syslog*:

# keep 4 weeks worth of backlogs
rotate 4

# uncomment this if you want your log files compressed
#compress


Important log files/locations

dmesg

http://www.cyberciti.biz/faq/ubuntu-linux-gnome-system-log-viewer/. Retrieved on 2007-05-11 11:18.

/var/log/messages : General log messages /var/log/boot : System boot log /var/log/debug : Debugging log messages /var/log/auth.log : User login and authentication logs /var/log/daemon.log : Running services such as squid, ntpd and others log message to this file /var/log/dmesg : Linux kernel ring buffer log /var/log/dpkg.log : All binary package log includes package installation and other information /var/log/faillog : User failed login log file /var/log/kern.log : Kernel log file /var/log/lpr.log : Printer log file /var/log/mail.* : All mail server message log files /var/log/mysql.* : MySQL server log file /var/log/user.log : All userlevel logs /var/log/xorg.0.log : X.org log file /var/log/apache2/* : Apache web server log files directory /var/log/lighttpd/* : Lighttpd web server log files directory /var/log/fsck/* : fsck command log /var/log/apport.log : Application crash report / log file

System Log Viewer (gnome-system-log)

http://www.cyberciti.biz/faq/ubuntu-linux-gnome-system-log-viewer/. Retrieved on 2007-05-11 11:18.

View log files using GUI tools using the GNOME System Log Viewer System Log Viewer is a graphical, menu-driven viewer that you can use to view and monitor your system logs. System Log Viewer comes with a few functions that can help you manage your logs, including a calendar, log monitor and log statistics display. System Log Viewer is useful if you are new to system administration because it provides an easier, more user-friendly display of your logs than a text display of the log file. It is also useful for more experienced administrators, as it contains a calendar to help you locate trends and track problems, as well as a monitor to enable you to continuously monitor crucial logs. You can start System Log Viewer in the following ways: Click on System menu > Choose Administration > System Log ...

NTFS

https://help.ubuntu.com/community/MountingWindowsPartitions

Ubuntu can read and write files on your Windows partition. Windows partitions are normally formatted as NTFS [...].


Inspecting the system configuration

See what flavor/distribution/version of GNU/Linux you're running

/etc/issue

# cat /etc/issue
Ubuntu 10.04.2 LTS \n \l

lsb_release

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.2 LTS
Release:        10.04
Codename:       lucid

/etc/*release* is often very helpful

In the case of Red Hat/Fedora:

 > cat /etc/redhat-release
Fedora Core release 4 (Stentz)

On my Ubuntu system, — Tyler (2008-05-07 18:42):

> ls /etc/*release*
/etc/lsb-release

> ls /etc/*version* -d
/etc/debian_version  /etc/subversion

> cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04"

> cat /etc/debian_version
lenny/sid

http://lists.debian.org/debian-devel/2006/02/msg00891.html. Retrieved on 2007-05-11 11:18.

Prior to etch I was using lsb-release but it seems /etc/lsb-release is no longer installed by 'apt-get install lsb-release'. The README.Debian file provides the following background information:

> Distribution-specific information should be *separately provided* in
> /etc/lsb-release; it is no longer provided in this package.  It is my
> hope that in Debian, this will be managed by the base-files
> maintainer (who already maintains the debian_version file).

I don't pretend to understand the reason for this change but I do know that my identification mechanism is now broken on etch.

Can anyone suggest a more reliable mechanism?

http://lists.debian.org/debian-devel/2006/02/msg00895.html. Retrieved on 2007-05-11 11:18.

I think that the most reliable will be checking libc version.

http://lists.debian.org/debian-devel/2006/02/msg00933.html. Retrieved on 2007-05-11 11:18.

How about to check/grep/process /etc/debian_version installed by base-files?

$ cat /etc/debian_version
testing/unstable

From http://www.fuschlberger.net/programs/ssh-scp-sftp-chroot-jail/make_chroot_jail.sh (http://www.fuschlberger.net/programs/ssh-scp-sftp-chroot-jail/)

# Check existence of necessary files
echo "Checking distribution... "
if [ -f /etc/debian_version ];
  then echo "  Supported Distribution found"
       echo "  System is running Debian Linux"
       DISTRO=DEBIAN;
elif [ -f /etc/SuSE-release ];
  then echo "  Supported Distribution found"
       echo "  System is running SuSE Linux"
       DISTRO=SUSE;
elif [ -f /etc/fedora-release ];
  then echo "  Supported Distribution found"
       echo "  System is running Fedora Linux"
       DISTRO=FEDORA;
elif [ -f /etc/redhat-release ];
  then echo "  Supported Distribution found"
       echo "  System is running Red Hat Linux"
       DISTRO=REDHAT;

uname is sometimes helpful

This shows the version of the Linux kernel, not of your distribution (although sometimes there is a hint about your distribution to be found there too)...

$ uname -r
2.6.7-gentoo-r10
$ uname -r
2.6.16-1.2069_FC4smp  [Fedora Core 4 Symmetric MultiProcessor]
# uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type
  -i, --hardware-platform  print the hardware platform
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

/proc/version -- Probably not the best source of distro information

This apparently shows the version of the Linux kernel (with the version of gcc in parentheses), not of your distribution...

> cat /proc/version 
Linux version 2.6.16-1.2069_FC4smp (bhcompile@hs20-bc1-7.build.redhat.com) (gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)) #1 SMP Tue Mar 28 12:47:32 EST 2006

CentOS 4 (based on RHEL 4) says this:

> cat /proc/version
Linux version 2.6.9-023stab046.2-enterprise (root@rhel4-32) (gcc version 3.4.5 20051201 (Red Hat 3.4.5-2)) #1 SMP Mon Dec 10 15:22:33 MSK 2007

But on my Ubuntu 8.04 system it doesn't mention Ubuntu 8.04 at all.

> cat /proc/version
Linux version 2.6.24-16-generic (buildd@yellow) (gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)) #1 SMP Thu Apr 10 12:47:45 UTC 2008

dmesg: print out the bootup messages

dmesg

How do I figure out which process is using a certain port?

Or: I'm getting a "cannot bind; address/port already in use" error and I'm not sure which process to kill because I don't see anything listed by ps that looks like it would be that port...

(Lance showed me this trick...)

sudo netstat -lnp

or

sudo netstat -pean

Look for the part number that is supposedly already in use; beside it, it show you which process id as well as which program that has tied up / is using that port. And then kill it:

kill -9 21457

uptime -- "Tell how long the system has been running."

man uptime


uptime gives a one line display of the following information. The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. This is the same information contained in the header line displayed by w(1). System load averages is the average number of processes that are either in a runnable or uninterruptable state. A process in a runnable state is either using the CPU or waiting to use the CPU. A process in uninterruptable state is waiting for some I/O access, eg waiting for disk. The averages are taken over the three time intervals. Load averages are not normalized for the number of CPUs in a system, so a load average of 1 means a single CPU system is loaded all the time while on a 4 CPU system it means it was idle 75% of the time.

[load average (category)]

System administration

Monitoring

This is just a little script I put in my crontab to collect stats about load, etc. It could probably be better, but hey, it's better than nothing!

#!/bin/bash
log_dir=/var/...
mkdir -p ${log_dir}
now=`date +%Y%m%dT%H%M`

echo -n "$now: " >> ${log_dir}uptime
uptime >> ${log_dir}uptime

echo "-----------------------------------" >> ${log_dir}ps
echo $now >> ${log_dir}ps
ps aux | grep 'PID\|mongrel\|rails' >> ${log_dir}ps

echo "-----------------------------------" >> ${log_dir}free
echo $now >> ${log_dir}free
free -m -o >> ${log_dir}free

echo "-----------------------------------" >> ${log_dir}top
echo $now >> ${log_dir}top
top -n1 | head -n 17 | sed 's/\[H//g'  | sed 's/\[6;1H//g' >> ${log_dir}top
                       # /\ removes the codes which position the cursor at the top of screen


Problem: Too many distributions

Solution: Standardize things

(This description of solutions also implicitly lists some of the problems that can and do result from having many competing choices: fragmentation, incompatibility, lack of interoperability, vendor lock-in, applications that lack portability, ...)

http://www.linux-foundation.org/en/LSB. Retrieved on 2007-05-11 11:18.

The Linux Standard Base delivers interoperability between applications and the Linux operating system. Currently all major distributions comply with the LSB and many major application vendors, like MySQL, RealNetworks and SAP, are certifying. The LSB offers a cost-effective way for application vendors to target multiple Linux distributions while building only one software package. For end-users, the LSB and its mark of interoperability preserves choice by allowing them to select the applications and distributions they want while avoiding vendor lock-in. LSB certification of distributions results in more applications being ported to Linux and ensures that distribution vendors are compatible with those applications. In short, the LSB ensures Linux does not fragment. If you are an end user looking for Linux distributions that support open standards, please see our list of LSB certified products. If you are a developer looking to build portable Linux applications that will work on these distributions, please see the Linux Developer Network.


Which distro should I use?

Ah yes, that question... one of the question that makes me hesitant to seriously consider switching completely to GNU.

So many choices... if only there were an obvious best choice!

Anyway, there isn't -- each one has its share of pros/cons -- so the best I can do is listen to the advice/recommendations of people I trust.

Recommendations

Ezra recommends Ubuntu for the desktop and Gentoo for the server.

I like Ubuntu.

nohup: Run a command immune to hangups

`nohup' runs the given COMMAND with hangup signals ignored, so that the
command can continue running in the background after you log out.
Synopsis:

     nohup COMMAND [ARG]...

   If standard input is a terminal, it is redirected from `/dev/null'
so that terminal sessions do not mistakenly consider the terminal to be
used by the command.  This is a GNU extension; programs intended to be
portable to non-GNU hosts should use `nohup COMMAND [ARG]... </dev/null'
instead.

   If standard output is a terminal, the command's standard output is
appended to the file `nohup.out'; if that cannot be written to, it is
appended to the file `$HOME/nohup.out'; and if that cannot be written
to, the command is not run.  Any `nohup.out' or `$HOME/nohup.out' file
created by `nohup' is made readable and writable only to the user,
regardless of the current umask settings.

   If standard error is a terminal, it is redirected to the same file
descriptor as the (possibly-redirected) standard output.

   `nohup' does not automatically put the command it runs in the
background; you must do that explicitly, by ending the command line
with an `&'.  Also, `nohup' does not alter the niceness of COMMAND; use
`nice' for that, e.g., `nohup nice COMMAND'.


daemontools

Dan Berstein's

http://cr.yp.to/daemontools.html

How I installed daemontools?

[root@studebaker ~]# yum install gcc

Put this script into file [root@studebaker ~]# ./install_daemontools.sh

    #!/bin/sh
    #
    # install daemontools on fedora/redhat linux
    #
    # Mike Jackson <mj@sci.fi> 5 NOV 2005
    #
    #
    mkdir /package
    chmod 1755 /package
    cd /package
    wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
    tar xzvf daemontools-0.76.tar.gz
    rm -f daemontools-0.76.tar.gz
    cd admin/daemontools-0.76/src
    wget http://www.qmailrocks.org/downloads/patches/daemontools-0.76.errno.patch
    patch < daemontools-0.76.errno.patch
    cd ..
    package/install

That script downloads, compiles, and installs it.

After that, this process will be forever running, watching over everything: root 5069 0.0 0.0 1564 336 ? S 10:54 0:00 svscan /service

How do we set up a new service?

Create a file /service/whatever/run: -rwxr--r-- 1 root root 126 Mar 16 11:24 run

That's it! svscan automatically starts the service as soon as it sees that run command.

How can I verify that it's running?

> ps aux | grep whatever
> svstatus /service/whatever/

freedt: Free Daemontools

http://offog.org/code/freedt.html

freedt is a reimplementation of Dan Bernstein's daemontools under the GNU GPL, sharing no code with the original implementation.

[GNU/Linux / Startup (category)] / Startup scripts

How do I get a program to start up automatically?

You can use GNOME's Session Preferences -> Startup Programs feature

Unless you want something lower-level...

When would GNOME's feature not be appropriate...?


What's the difference between rc and init?

...

init.d

You can write init.d scripts in bash or even [Ruby (category)]...

Peter Cooper. How to create a UNIX /etc/init.d startup script with Ruby (http://www.rubyinside.com/how-to-create-a-unix-etcinitd-startup-script-with-ruby-250.html). Retrieved on 2007-03-26 16:16.

Or see my example here: http://svn.tylerrick.com/public/ruby/init.d

Miscellaneous

[Troubleshooting (category)] Can’t write viminfo file $HOME/.viminfo when doing sudo vim on Debian/Ubuntu

[Vim (category)]

I first noticed this on an Ubuntu box on which I was given root. Whenever I would sudo vim something, it would not have syntax highlighting turned on, even though /root/.vimrc had syntax on. In fact, it looked like it wasn't reading/using the .vimrc file at all. And when I would exit vim, I would get this error:

E138: Can’t write viminfo file $HOME/.viminfo!

[Solution (category)]:

Add env_reset to the Defaults line in your /etc/sudoers file. For example:

Defaults whatever,some_thing,env_reset

Credit for solution: http://stateless.geek.nz/2006/01/24/sudo-upgrade-from-debian-security-changes-env-handling/


What does it need to do to win in the OS desktop market?

Mono developer brings the Ribbon interface to Linux (http://arstechnica.com/journals/linux.ars/2007/08/30/mono-developer-brings-the-ribbon-interface-to-linux). Retrieved on 2007-05-11 11:18.

danchr,August 30, 2007 @ 09:40PM

I can't help but wonder, what were their thoughts prior to copying Microsoft? Do they copy Microsoft uncritically, or do they copy Microsoft because they offer the best solution? It strikes me as an odd choice if the goal of the Mono developers is to copy Microsoft. Copying will mean that they will always be one step behind whomever they are copying. I wish Linux could offer a serious alternative to Microsoft, and to do so, they would have to offer something clearly superior. Being similar, but better, won't cut it. However, it seems that most Linux developers are so entrenched in our Microsoft world that they don't look elsewhere for inspiration. Maybe the Ribbon is a good idea; maybe it isn't. Did they analyse it prior to copying it? Did they do any usability studies prior to implementing it? Where there any reasons for implementing it other than saying “We're better than Microsoft, and can do whatever they do!” to themselves? Abolishing the menu bar is a decision which will effect users significantly. Such a decision should not be taken lightly and should only be taken if the replacement is clearly superior. Fundamentally, developers aren't the ones which should be making such a decision; most developers have little experience and knowledge when it comes to usability. Developers should be following the directions of usability experts in an area such as this. Did they do so? This strikes me as yet another instance of the fundamental problems of the Linux platform: the lack of goal. Or rather, that the apparent goal of being a better Windows than Windows is fundamentally flawed. If you want to create a good user interface, you might want to look elsewhere for inspiration. The products of Microsoft aren't generally renowned for optimum usability. Niche operating systems like Mac OS X might offer suggestions, and even more obscure operating systems might offer alternate approaches which could make Linux diversify itself. For instance, when GNOME chose to promote the spatial metaphor for the file manager, it was a conscientious and bold — but also risky — decision. Such decisions should be applauded. Personally, I prefer Linux to Microsoft Windows. However, it seems that Linux is positioning itself as a discount operating system. It's not sufficiently superior to the other major systems to be chosen on merit alone, and thus its price (or lack thereof) is its main feature. I find that sad. Mac OS X is much more expensive to obtain than Linux, yet it has a higher market share. I'm certain that sexy hardware and better marketing aren't the only reasons for this. Please, make me tempted by your OS; I beg you! (For the record, I use Mac OS X myself.)

August 31, 2007 @ 01:23AM

Why settle for discount? Why settle at all? Why isn't Linux more competitive, and why doesn't it have any bullet points where it blows Windows Vista away? While there is little innovation in basic UI concepts, there's a lot of innovation in concrete UI. Additionally, some of the old concepts might be worth reconsidering. For instance, Mac OS X has had pervasive drag and drop for a long time; maybe this an area where Linux could improve?


GNU/Linux / Sources

GNU/Linux / Sources edit


http://www.chimeric.de/

http://ubuntu-tutorials.com

http://wp.uberdose.com/

http://flipsidereality.com/blog/category/nix/

http://www.burtonini.com/blog/

http://h3g3m0n.wordpress.com/

http://tuxtoday.wordpress.com/

This blog is dedicated to free and open source software, and also freely licensed media, such as music, movies and e-books. I'm no expert, but I would like to contribute with the knowledge that I do have. - Johan.

http://aplawrence.com/index.html

"Information and Resources for Unix and Linux Systems Bloggers and the self-employed"

---

http://simplix.blogspot.com/

The SimpliX is a small volunteer community of people that are Linux/BSD users and want to help the newbies to switch to XOSes or have fun with them.

http://www.newlinuxuser.com/

 



History

http://liw.iki.fi/liw/texts/linux-anecdotes.html


News

Ads
Personal tools