Script12 Apr 2009 09:24 pm

#! / bin / csh
#
# In some cases, need to e-mail sent to all users on the system.
# Alerts the user when the hardware upgrade of the information is a good example.
# The messages were sent to each user is a waste of time,
# this is the invention of e-mail aliases and mailing list of a task.
# But the recording system on the mailing list for all users is a problem,
# if the lazy update mailing list, then add and remove
# Users on the most accurate; If there are many users,
# then the other it is difficult to control the size of the list.
#
# The following script called mailfile, to solve these problems provides a simple way.
# It can be directly from the / etc / passwd file access login name and e-mail sent to all users.
#
# Mailfile: This script mails the specified file to all users
# Of the system. It skips the first 17 accounts so
# We do not send the email to system accounts like
# ‘Root’.
#
# USAGE: mailfile “Subject goes here” filename.txt

#
# Check for asubject
#
if ( `echo $ 1 | awk ‘(print $ 1)’` == “”) then
echo You did not supply a subject for the message.
echo Be sure to enclose it in quotes.
exit 1
else
# Get the subject of the message
set subject = $ 1
endif

#
# Check for a filename
#
if ($ 2 == “”) then
echo You did not supply a file name.
exit 2
else
# Get the name of hte file to send
set filename = $ 2
endif

#
# Check that the ifle exists
#
if (-f $ filename) then
echo Sending file $ filename
else
echo File does not exist.
exit 3
endif

#
# Loop through every login name, but skip the first 17 accounts
#
foreach user ( `awk-F: ‘(print $ 1)’ / etc / passwd | tail +17`)
# Mail the file
echo Mailing to $ user
mail-s “$ subject” $ user <$ filename

# Sleep for a few seconds so we don; t overload the mailer
# On fast systems or systems with few accounts, you can
# Probably take this delay out.

sleep 2
end

The script receives two parameters, first one is the subject of the message, which is included in quotation marks; second one is to send a message that contains the text of the file name. Therefore, it is necessary to e-mail sent to all users, warning users to upgrade server hardware and ordered as follows:

mailfile “System upgrade at 5: pm” upgrade.txt

file contains upgrade.txt send text messages to all users. This method is where the real purpose of the text file can be saved and a simple modification, the next upgrade system can be re-sent it.

Tip: If the user login to use text-based rather than graphical login, you can add to the e-mail / etc / motd file, and so that they can reach the user. The document will be any text after the user logs in and before the appearance of a shell prompt, displayed in each user’s screen.

Script11 Oct 2008 12:24 pm

Zombie Process is the son of the process due to the introduction of the service did not use the process of collecting wait-function state of the process of arising. Zombie is a process, the process has come to an end, do not take up the memory system resources, CPU time for little or no impact, but the process will take place in the table. As the process of table space is limited, Linux systems have a number of the process is limited, too many zombie process will affect the process of the new generation.

Zombie process exists to give programmers and system administrators to provide some important information in the process. This information, including how the end of the process, in the course of operation as to whether there was an error, and so on. If there is no zombie process, which will end with the process of disappearing. As a result, the process of carrying the corpse of information for programmers and systems administrators found that the procedure has a problem of great significance.

I wrote a simple zpro.c output of the process of zombie code sample:

# include <stdlib.h>
# include <sys/types.h>
# include <unistd.h>

int main (void)
{
pid_t pid;

pid = fork();
if(pid<0){
perror(”Cannot create new process”);
exit(1);
}

if (pid>0)
sleep (60);
else
exit(0);
return 0;
}

Gcc compiler to use the above procedure zpro.c, a zpro executable file. In the background of the implementation of procedures and the use of ps command to view information related to the process. Can see the zpro process in the process of the list of state for the zombie process.

[netspy@localhost ~]$ gcc -c zpro zpro.c
[netspy@localhost ~]$ ./zpro &
[1]  6031
[netspy@localhost ~]$ ps -e -o pid,ppid,stat,cmd |grep zpro
6031  3729 S   ./p7.18
6032  6031 Z   [zpro] <defunct>
6037  3729 S+  grep zpro
[netspy@localhost ~]$

To understand the causes of the zombie process, it is easy to clear the process of zombies. In the Linux system, each process is the father of the existence of the process. If the Father of the process of being switched off, the son of the process will become orphans by the process of taking over the process of init. If the child process for the zombie, then the process, init process will be responsible for the clean-up. In other words, turn off the corpse as long as the process of the father of the process, it is clear zombie process.

My Files08 Oct 2008 09:49 am

I’m Glad you have free time to visit my Blog. Today I was once again to install and use Ubuntu Linux system. I love the system and not leave it. I would have to come to this Blog I record after learning of Linux experience and skills of inspiration. And decided to use English to write the article. This looks better! :P