linux poison RSS
linux poison Email
0

Bash Script: Write debugging information to /var/log/messages

logger is a shell command interface to the syslog system log module, it appends a user-generated message to the system log (/var/log/messages). You do not have to be root to invoke logger.

Below is the simple bash script to log the debugging information to /var/log/message
Feel free to copy and use the below code

Source: cat logger.sh
#!/bin/bash

echo -n "Enter your username: "
read username

logger -i "Username $username started the script"

echo -n "Enter your Password: "
read password

# This is just an sample for comparing the password
if [ "$password" = "linuxpoison" ]; then
        echo "welcome $username"
        logger -i "Authentication successful for $username."
else
        echo "your Username or password does not match"
        logger -i "Authentication failed for $username."
fi

Read more
0

Bash Script: Set the timeout for reading the user input

If TMOUT set to a value greater than zero, TMOUT is treated as the default timeout for the read builtin.  The select command terminates if  input does  not arrive after TMOUT seconds when input is coming from a terminal. 

In an interactive shell, the value is interpreted as the number of seconds to wait for input after issuing the primary prompt.  Bash terminates after waiting for that number of seconds if input does  not arrive.

Below is the bash script which explains the above concept ...
Feel free to copy and use this script

Source: cat timeout.sh
#!/bin/bash

TMOUT=5
echo -n "Enter you username: "
read username

if [[ -z $username ]]; then
        # No username provide
        username="Not Set"
        echo "Timeout, Run this script again and set your valid username..."
fi


Output: ./timeout.sh
Enter you username: Timeout, Run this script again and set your valid username...
Read more
0

Bash Script: Running part of the script in restricted mode

If Bash is started with the name rbash, or the --restricted or -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. A restricted shell behaves identically to bash with the exception that the following are disallowed or not performed:

 * Changing directories with the cd built-in.
 * Setting or unsetting the values of the SHELL, PATH, ENV, or BASH_ENV variables.
 * Specifying command names containing slashes.
 * Specifying a filename containing a slash as an argument to the . built-in command.
 * Specifying a filename containing a slash as an argument to the -p option to the hash built-in command.
 * Importing function definitions from the shell environment at startup.
 * Parsing the value of SHELLOPTS from the shell environment at startup.
 * Redirecting output using the ‘>’, ‘>|’, ‘<>’, ‘>&’, ‘&>’, and ‘>>’ redirection operators.
 * Using the exec built-in to replace the shell with another command.
 * Adding or deleting built-in commands with the -f and -d options to the enable built-in.
 * Using the enable built-in command to enable disabled shell built-ins.
 * Specifying the -p option to the command built-in.
Read more
0

Free eBook - The GNU/Linux Advanced Administration

"The GNU/Linux Advanced Administration"


The GNU/Linux systems have reached an important level of maturity, allowing to integrate them in almost any kind of work environment, from a desktop PC to the sever facilities of a big company.

In this ebook "The GNU/Linux Operating System", the main contents are related with system administration. You will learn how to install and configure several computer services, and how to optimize and synchronize the resources using GNU/Linux.

The topics covered in this 500+ page eBook include Linux network, server and data administration, Linux kernel, security, clustering, configuration, tuning, optimization, migration and coexistence with non-Linux systems. A must read for any serious Linux system admin.

Download your free copy of "The GNU/Linux Advanced Administration" - here


Read more
1

Free eBook - HA Solutions for Windows, SQL, and Exchange Servers

"HA Solutions for Windows, SQL, and Exchange Servers".

How to protect your company's critical applications by minimizing risk to disasters with high availability solutions.

When total data loss is possible, the absence of a disaster recovery program can put a business at risk. Although disasters are inevitable and, to a degree, unavoidable, being prepared for them is completely within your control.

Increasingly, IT has become the focal point of many companies' disaster planning. Creating a program to preserve business continuity and recover from disaster is one of the central value propositions that an IT department can contribute to an organization.

Download you free HA Solutions for Windows, SQL, and Exchange Servers eBook - here


Read more
Related Posts with Thumbnails