ie if you have the following piece of code:
currdir=`pwd`
and want to replace it with
currdir=$(pwd)
then, in Notepad++ use the following in the find and replace menu:
Find: `(.*)`
Replace: \$\($1\)
currdir=`pwd`
currdir=$(pwd)
yum install gcc gcc-c++ autoconf automake
Then install the command itself:
wget http://pkgs.fedoraproject.org/repo/pkgs/stress/stress1.0.4.tar.gz/a607afa695a511765b40993a64c6e2f4/stress-1.0.4.tar.gz
tar zxvf stress-1.0.4.tar.gz
cd stress-1.0.4
./configure
make
make install
To do the stress tests themselves:
stress –c 5 –t 1200s
Stress Memory for 10 minutes
stress –m 10 –t 1200s
Stress disk io for 10 minutes
stress –d 10 –t 1200s
The first command will push CPU to 500%. It only works on one core, so it may need to run several time simultaneously, depending on how many cores there are. The second command produces 10 spinning process, and the third 10 spinning disk write processes.
#!/bin/bash
if [ $1 ]; then
NUM_PROC=$1
else
NUM_PROC=10
fi
uptime
for i in $(seq 1 $NUM_PROC ); do
awk 'BEGIN {for(i=0;i<10000;i++)for(j=0;j<10000;j++);}' &
pidarr[$i]=$!
echo ${pidarr[$i]}
done
ps -fp "${pidarr[*]}"
uptime
We can use dd and a variation of the above script to thrash the disk IO:
#!/bin/bash
if [ $1 ]; then
NUM_PROC=$1
else
NUM_PROC=10
fi
for i in $(seq 1 $NUM_PROC ); do
dd if=/dev/sda of=/dev/null &
pidarr[$i]=$!
echo ${pidarr[$i]}
done
ps -fp "${pidarr[*]}"
And for memory, we can use another variation:
#!/bin/bash
if [ $1 ]; then
NUM_PROC=$1
else
NUM_PROC=2
fi
BS=$(free | grep "^Mem" | awk '{print $2}' | head -1)
for i in $(seq 1 $NUM_PROC ); do
dd if=/dev/urandom bs=$BS of=/dev/null count=1050 &
pidarr[$i]=$!
echo ${pidarr[$i]}
done
ps -fp "${pidarr[*]}"
This caches huge blocks of random numbers (using a block size of the total amount of used space in the system). Doing it a couple of times simultaneously will do the trick.
$ ./dbusers.sh -s UC1 -rUC2 user1 user2 user3
./dbusers.sh: line 33: $'\r': command not found
./dbusers.sh: line 36: syntax error near unexpected token `$'in\r''
'/dbusers.sh: line 36: ` case $value in
This can be fixed in notepad++ in the Settings menu:
sed -i 's/\r\n/\n/g' <script>
This simple sed command searches for <linefeed><carriage return> (\r\n) and replaces it with a simple <carriage return> (\n).NAME=amypond
CORES=2
IF1=hre228001
IF2=hre229001
ADD1=172.21.138.107
ADD2=172.21.139.107
zonecfg -z $NAME <<EOF
create
set zonepath=/zones/$NAME
set autoboot=true
set bootargs="-m verbose"
add dedicated-cpu
set ncpus=$CORES
end
add net
set physical=$IF1
set address=$ADD1
end
add net
set physical=$IF2
set address=$ADD2
end
info
verify
commit
EOF
zoneadm -z $NAME install
zoneadm -z $NAME ready
zoneadm -z $NAME boot
add fs
set dir=/mnt
set special=/cdrom
set type=lofs
add options [ro,nodevices]
end
add inherit-pkg-dir
set dir=/opt/sfw
end
add capped-memory
set physical=50m
set swap=100m
set locked=30m
end
zlogin -C $NAME
sudo date| user | The name of the user being granted access |
| host | A host on the network. For all hosts, use ALL. |
| command | A list of one or more commands, qualified by options such as whether the password is required. For all commands, use ALL. |
paul ALL = ALL
paul beatle = (ringo) ALL| NOPASSWD / PASSWD | Determines whether or not the user will require a password to run the command. |
| NOEXEC / EXEC | If sudo has been compiled with noexec support, this determines whether or not an executable will be allowed to run further commands itself. |
| SETENV / NOSETENV | Determines whether or not users are allowed to override environment variables with the sudo -e command. |
| LOG_INPUT / NOLOG_INPUT | Determines whether or not the input to the command is written to the log file. |
| LOG_OUTPUT / NOLOG_OUTPUT | Determines whether or not the output from the command is written to the log file. |
paul beatle = PASSWD: /usr/bin/kill, NOPASSWD: /usr/bin/lprm
sudo -l
su -yum -y install httpdchkconfig httpd onservice httpd start
<html>
<head>
<title>Dougie's Linux Hints Test Web Page</title>
</head>
<body>
This is a test Web Page.
</body>
</html>
elinks http://localhostyum groupremove “X Window System”| Option | Description |
|---|---|
| noexec | Prevents the execution of binaries (although scripts will not be prevented from running). |
| nosuid | Prevents the setuid bit from having an effect. |
| nodev | Prevents the use of device files. |
/dev/sda5 /ftpdata ext3 defaults 1 2/dev/sda5 /ftpdata ext3 defaults,nosuid,nodev,noexec 1 2/sbin/grub-md5-cryptpassword --md5 <password-hash>
<module interface> <control flag> <module name> <module arguments>
| Module Interface | Definition |
|---|---|
| auth | This module interface authenticates use. For example, it requests and verifies the validity of a password. Modules with this interface can also set credentials, such as group memberships or Kerberos tickets. |
| account | This module interface verifies that access is allowed. For example, it may check if a user account has expired or if a user is allowed to log in at a particular time of day. |
| password | This module interface is used for changing user passwords. |
| session | This module interface configures and manages user sessions. Modules with this interface can also perform additional tasks that are needed to allow access, like mounting a user's home directory and making the user's mailbox available. |
| Control Flag | Definition |
|---|---|
| required | The module result must be successful for authentication to continue. If the test fails at this point, the user is not notified until the results of all module tests that reference that interface are complete. |
| requisite | The module result must be successful for authentication to continue. However, if a test fails at this point, the user is notified immediately with a message reflecting the first failed required or requisite module test. |
| sufficient | The module result is ignored if it fails. However, if the result of a module flagged sufficient is successful and no previous modules flagged required have failed, then no other results are required and the user is authenticated to the service. |
| optional | The module result is ignored. A module flagged as optional only becomes necessary for successful authentication when no other modules reference the interface. |
| include | Unlike the other controls, this does not relate to how the module result is handled. This flag pulls in all lines in the configuration file which match the given parameter and appends them as an argument to the module. |
passwd -l username
passwd -u username
awk -F: '($2 == "") {print $1}' /etc/shadow
passwd -l <Account Name>
chage -l username
chage -M 60 -m 7 -W 7 <username>
| Option | Description |
|---|---|
| -m | Minimum number of days a user must go before being able to change their password |
| -M | Maximum number of days a user can go without changing their password |
| -d | The last day the password was changed |
| -E | Specific expiration date for a password, date in format YYYY-MM-DD or MM/DD/YYYY |
| -I | Allowable account inactivity period (in days) after which password will expire |
| -W | Warning period. The number of days before expiration when the user will be sent a warning message |
| -l | Display current expiration controls |
touch /etc/security/opasswd
chown root:root /etc/security/opasswd
chmod 600 /etc/security/opasswd
auth sufficient pam_unix.so likeauth nullok
password sufficient pam_unix.so nullok use_authtok md5 shadow remember=5
/lib/security/$ISA/pam_cracklib.so retry=3 minlen=8 lcredit=-1 ucredit=-2 dcredit=-2 ocredit=-1
/sbin/chkconfig sshd offPermitRootLogin yes
AllowUsers john paul george ringo
groupadd sshusers
usermod -aG sshusers john
usermod -aG sshusers paul
usermod -aG sshusers george
usermod -aG sshusers ringo
AllowGroups sshusersNote:- The Internet Assigned Numbers Authority (IANA) is responsible for the global coordination of the DNS Root, IP addressing, and other Internet protocol resources. It is good practice to follow their port assignment guidelines. Having said that, port numbers are divided into three ranges: Well Known Ports, Registered Ports, and Dynamic and/or Private Ports. The Well Known Ports are those from 0 through 1023 and SHOULD NOT be used. Registered Ports are those from 1024 through 49151 should also be avoided too. Dynamic and/or Private Ports are those from 49152 through 65535 and can be used.Choose an appropriate port, also making sure it not currently used on the system, and update the following line in /etc/ssh/sshd_config:
Port <New Port Number>service sshd restart
wget http://software77.net/geo-ip/?DL=1 -O ./IpToCountry.csv.gz
gunzip -c IpToCountry.csv.gz | awk -F, '!/^#/ {gsub(/"/, "", $0);print $1, $2, $5}' > ./IpToCountry.csv
<?php
//-
$ranges=Array(
"IP From" => array("IP To","2-Digit Country Code")
);
?>
#!/bin/bash
#######################################################
#
# csv2IP.sh
#
# Douglas Milne 2 June 2014
#
# Download a csv file of IP address ranges for countries
# and convert to php arrays
#
#######################################################
# create a temporary directory to build the files
# Files are built here, then moved to the correct location on completion
# This minimizes the amount of time the files are unavailable as recreating them can take several minutes
mkdir ~/iptemp 2>/dev/null
cd ~/iptemp
# Download the csv file
wget http://software77.net/geo-ip/?DL=1 -O ./IpToCountry.csv.gz >/dev/null 2>&1
status=$?
if (( status != 0 ))
then
echo "Error downloading csv file"
exit 2
fi
# Uncompress the CSV file and select only the To, From and Country columns
gunzip -c IpToCountry.csv.gz | awk -F, '!/^#/ {gsub(/"/, "", $0);print $1, $2, $5}' > ./IpToCountry.csv
# Create a new .php file for the first digit of possible ip addresses, ie 0-255, and write a header to it
for ((i=0; i<=255; i++))
do
echo -e "<?php\n//-\n\$ranges=Array(" > $i.php
done
# Add the IP ranges as specified in the CSV file to the php files.
# The first digit of each ip address, and therefore the file to write to,
# is determined by the integer result of dividing the address by 16777216
cat IpToCountry.csv | awk '{print $1,$2,$3}' | while
read ipFrom ipTo Country
do
(( ipmsb = ipFrom / 16777216 ))
echo -e "\"$ipFrom\" => array(\"$ipTo\",\"$Country\")," >> $ipmsb.php
done
# Add a footer to each of the php files
# and move the files to the correct location.
for ((i=0; i<=255; i++))
do
echo -e ");\n?>" >> $i.php
mv $i.php ~/ip_files
done
$ cat 45.php
<?php
//-
$ranges=Array(
"754974720" => array("755105791","US"),
"757071872" => array("759169023","ZZ"),
"765460480" => array("767557631","UY"),
);
?>
function iptocountry($ip) {
$numbers = preg_split( "/\./", $ip);
include("ip_files/".$numbers[0].".php");
$code=($numbers[0] * 16777216) + ($numbers[1] * 65536) + ($numbers[2] * 256) + ($numbers[3]);
foreach($ranges as $key => $value){
if($key<=$code){
if($ranges[$key][0]>=$code){$two_letter_country_code=$ranges[$key][1];break;}
}
}
return $two_letter_country_code;
}
$two_letter_country_code=iptocountry($_SERVER['REMOTE_ADDR']);
#!/bin/ksh
##################################################################
#
# fsfree.ksh
#
# Purpose: To display free space on each filesystem on a server
# and to warn if it falls below a certain percentage.
#
# Return status:
# 0 All filesystem space is above the limit
# 1 One or more filesystems are below the limit
# 2 The script has not been correctly executed
#
# Syntax: fsfree.ksh [ -a ] [ -g | -m | -p ] [ -h ] [-q ]
# [ -l limit | -f file ]
#
# Flags
# -a Displays all filesystems
#
# By default, the script will display only those
# filesystems which are below the limit.
#
# -f Use the specified file to define the limits
# for the individual filesystems
#
# The format of the file should be:
# Filesystem Limit
#
# An initial file may be generated using the
# free command as follows:
#
# fsfree.ksh -pal 0 > limitfile.dat
#
# The file should then be edited as appropriate
#
# -g Displays total and free space in Gigabytes
#
# Space is displayed in Kilobytes by default
#
# -h Output is in html format
#
# -l When the percentage free on the filesystem falls
# below the value of 'limit', the filesystem will be
# highlighted on the output.
#
# The default limit is 10%
#
# -m Displays total and free space in Megabytes
#
# Space is displayed in Kilobytes by default
#
# -p Total and free space is not displayed
#
# -q Quiet mode. No output is displayed.
#
# Author: Douglas Milne
# Date: 13th May 2008
#
##################################################################
#
# Version 1.0 Initial Release
#
##################################################################
##################################################################
#
# VARIABLES Section
#
#
# Set default variables
#
dispall=false
htmflag=false
pcntonly=false
quietmode=false
limitsource=default
divisor=1
stype="Kb"
scale=0
dlimit=10
returnstat=0
errstring=""
# Parse the flags and change default variables accordingly
while getopts :ahpgml:f:q value
do
case $value in
a) dispall=true
;;
h) htmflag=true
;;
p) pcntonly=true
;;
g) divisor=1048576
stype="Gb"
scale=3
;;
m) divisor=1024
stype="Mb"
scale=3
;;
l) if $(echo $OPTARG | grep -q [0-9])
then
dlimit=$OPTARG
limitsource=limit
else
errstring="Limit must be a number between 1 and 100"
dlimit=""
fi
;;
f) limitfile=$OPTARG
limitsource=file
if [ ! -f $limitfile ]
then
errstring="The file $limitfile does not exist"
fi
;;
q) quietmode=true
;;
\?) errstring="$0: unknown option $OPTARG"
;;
esac
if [ "$value" == ":" ]
then
case $OPTARG in
l) errstring="Limit argument must be included and must be a number between 1 and 100"
;;
f) errstring="The name of the file may not be blank"
;;
esac
fi
done
shift $(expr $OPTIND - 1)
##################################################################
#
# FUNCTIONS Section
#
syntaxerr ()
##################################################################
#
# Syntax: syntaxerr error
#
# error Text describing the error
#
# Writes a copy of the error and the syntax of the script
# to stderr.
#
##################################################################
{
err=$1
echo "$err\n\nSyntax: fsfree.ksh [ -a ] [ -g | -m | -p ] [ -h ] [-q ]\n [ -l limit | -f file ]\n" >&2
exit 2
}
limitdef ()
##################################################################
#
# Syntax: limitdef filesystem
#
# filesystem A filesystem name
#
# The function will return the limit required for the given
# filesystem. This may be the default limit, the limit defined
# from the command line, or the limit defined in the limitfile
#
##################################################################
{
fs=$1
case $limitsource in
default) echo $dlimit
;;
limit) echo $dlimit
;;
file) lim=$(grep ^/ $limitfile | grep "^$fs " | sort | head -1 | awk '{print $2}' | sed -e's/\%//g')
if [ "$lim" == "" ]
then
echo $dlimit
else
echo $lim
fi
;;
esac
}
display ()
##################################################################
#
# Syntax: display text
#
# text The text to display
#
# The function will print the text to the standard output, but
# only if the script is not running in quiet mode
#
##################################################################
{
text=$1
if [ $quietmode == false ]
then
echo "$text"
fi
}
##################################################################
#
# MAIN Section
#
# Error checking
if [ "$errstring" != "" ]
then
syntaxerr "$errstring"
fi
# Display the header
if [ $htmflag == true ]
then
# If html format is required, then create the head and body of the
# html page.
#
# A table is used to format the output. Define the table, and output
# the header.
#
display "<html><head>"
# Instead of below, it might be useful to cat in a standard css file instead
display "<style> th{font:10pt Arial;font-weight:bold;color:blue;background-color:LightBlue;padding-left:10px;padding-right:10px;} p{font:10pt Arial;} li{font:10ptArial;} td{font:10pt Arial;padding-left:10px;padding-right:10px;} .normal{color:black;} .alert{color:red;font-weight:bold;} .code{font:10pt Courier;color:black;}</style>"
display "</head><body>"
display "<p class=\"normal\">$(hostname) filesystem status at $(date)"
if [ $limitsource != "file" ]
then
display "<br><br>Limit is $dlimit%"
fi
display "</p>"
else
display "\n$(hostname) filesystem status at $(date)\n"
if [ $limitsource != "file" ]
then
display "Limit is $dlimit%\n"
fi
fi
if [ $htmflag == true ]
then
#
# A table is used to format the output. Define the table, and output
# the header.
#
display "<table>"
display "<tr>"
display "<th style=\"text-align: left\">Mount Point</th>"
if [ $pcntonly = false ]
then
#
# Only output the total Free and Total Size headers if the -p flag
# has not been used
#
display "<th style=\"text-align: right\">Total<br> Free ($stype)</th>"
display "<th style=\"text-align: right\">Total<br> Size ($stype)</th>"
fi
display "<th style=\"text-align: right\">%age<br> Free</th>"
if [ $limitsource == "file" ]
then
display "<th style=\"text-align: right\">%age<br>Limit</th>"
fi
display "</tr>"
else
# If html format is not required, then output the header as standard
boldon=$(tput smso)
boldoff=$(tput rmso)
typeset -L20 mntpnt
typeset -R11 free total
typeset -R3 pcnt limit
display "Mounted on \c"
if [ $pcntonly = false ]
then
#
# Only output the total Free and Total Size headers if the -p flag
# has not been used
#
display " Free ($stype) Total ($stype)\c"
fi
display " %Free\c"
if [ $limitsource == "file" ]
then
display " Limit"
else
display
fi
fi
df -k > /tmp/freedf
#
# For each filesystem in turn, read the mountpoint, total free
# space and total size
#
cat /tmp/freedf | tail +2 | awk '{print $7,$3,$2}' | while
read mntpnt free total
do
# If numeric values have been read, then calculate the output
if $( echo $free | grep -q [0-9])
then
# 1) Calculate the percentage of free space
let pcnt=free\*100/total
# 2) Calculate the free and total space as Kb, Mb or Gb as required
free=$(echo "scale=$scale; $free / $divisor" | bc)
total=$(echo "scale=$scale; $total / $divisor" | bc)
limit=$(limitdef $mntpnt)
# If the percentage free is less than the limit allowed, then switch on
# highlighting. For html output, use the alert class. For standard output,
# use bold type. Set the return status to 1.
if (( pcnt <= limit ))
then
if [ $htmflag == true ]
then
class=alert
else
display "$boldon\c"
fi
returnstat=1
else
# If the percentage free is greater than the limit allowed, then use the
# normal html class. This irrelevalnt for non-html output
class=normal
fi
if [ $dispall == true -o $pcnt -le $limit ]
then
if [ $htmflag == true ]
then
# If using html output, then create a table row
display "<tr>"
display "<!-- Mount Point -->"
display "<td class=\"$class\">$mntpnt</td>"
if [ $pcntonly = false ]
then
# Only display free and total size if they are required
display "<!-- Free Space -->"
display "<td class=\"$class\" style=\"text-align: right;\">$free</td>"
display "<!-- Total Space -->"
display "<td class=\"$class\" style=\"text-align: right;\">$total</td>"
fi
display "<!-- Percentage Free -->"
display "<td class=\"$class\" style=\"text-align: right;\">$pcnt%</td>"
if [ $limitsource == "file" ]
then
display "<!-- Limit -->"
display "<td class=\"$class\" style=\"text-align: right\">$limit%</td>"
fi
display "</tr>"
else
# If using standard output, write a row.
display "$mntpnt \c"
if [ $pcntonly = false ]
# Only display free and total size if they are required
then
display "$free $total \c"
fi
display "$pcnt% \c"
if [ $limitsource == "file" ]
then
display "$limit%\c"
fi
if (( pcnt <= limit ))
then
display "$boldoff"
else
display
fi
fi
fi
else
# if the values read were not numeric, then do not perform any calcualtions
# simply output them as read.
if [ $dispall == true ]
then
if [ $htmflag == true ]
then
class="normal"
display "<tr>"
display "<!-- Non numeric values read -->"
display "<td class=\"$class\">$mntpnt</td>"
if [ $pcntonly = false ]
then
display "<td class=\"$class\" style=\"text-align: right;\">$free</td>"
display "<td class=\"$class\" style=\"text-align: right;\">$total</td>"
fi
display "</tr>"
else
if [ $pcntonly = false ]
then
display "$mntpnt $free $total"
else
display "$mntpnt"
fi
fi
fi
fi
done
if [ $htmflag == true ]
then
# If using html output, close the table and the html page
display "</table></body></html>"
fi
return $returnstat
#
#############################################################
#!/usr/bin/bash
##################################################################
#
# htmmail
#
# Purpose: To send html formatted emails
#
# Syntax: htmmail [-s Subject] address [address] [address...]
#
# Subject The subject of the email
# address The email address of the intended recipient
#
# The content of the email may be included by piping it
# into the htmmail command.
#
# Author: Douglas Milne
# Date: 27th May 2014
#
##################################################################
#
# Version 1.0 Initial Release
#
##################################################################
# Get options
# s flag argument is the subject of the email
#
while getopts s: value
do
case $value in
s) SUBJECT=$2
;;
\?) echo "$0: unknown option $OPTARG"
;;
esac
done
shift $(expr $OPTIND - 1)
# Remaining arguments are email addresses to send the email
TO=$*
# Set up email header, including content type field
# signifying html format.
# To and Subject as specified above
/usr/lib/sendmail -t << EOF
mime-version: 1.0
content-type: text/html; charset="iso-8859-1"
To: $TO
Subject: $SUBJECT
$(cat)
EOF
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
ca::ctrlaltdel:/bin/echo "CTRL-ALT-DEL is disabled"
init q
for x in $(ls); do du -h $x | tail -1; done
GET /path/to/file/index.html HTTP/1.0
User-Agent: Mozilla /5.0 (Compatible MSIE 9.0;Windows NT 6.1;WOW64; Trident/5.0)
Accept: text/plain, text/html
Content-Type: text/plain
HTTP/1.0 200 OK
or
HTTP/1.0 404 Not Found
| Status Code | Explanation |
|---|---|
| 1** indicates an informational message only | |
| 100 - Continue | The client should send the remainder of the request |
| 101 - Switching Protocols | The server will switch protocols to those defined following header |
| 2** indicates success of some kind | |
| 200 - OK | The request succeeded |
| 204 - No Content | The document contains no data |
| 3** redirects the client to another URL | |
| 301 - Moved Permanently | The resource has permanently moved to a different URI |
| 4** indicates an error on the client's part | |
| 401 - Not Authorized | The request needs user authorization |
| 403 - Forbidden | The server has refused to fulfil the request |
| 404 - Not Found | The requested resource does not exist on the server |
| 408 - Request Timeout | The client failed to send a request in the time allowed by the server |
| 5** indicates an error on the server's part | |
| 500 - Server Error | Due to a malfunctioning script, server configuration error or similar |
Server: Apache/2.4.5
Last Modified: Wed, 20 Nov 2013 13:33:59 GMT