chmod [OPTION]... MODE[,MODE]... FILE...
Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:
4 stands for "read",
2 stands for "write",
1 stands for "execute", and
0 stands for "no permission."
So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
chmod [OPTION]... MODE[,MODE]... FILE...
Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:
4 stands for "read",
2 stands for "write",
1 stands for "execute", and
0 stands for "no permission."
So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
hmmm first bash post and it's for windows, how does that work ?
still here it is
install cygwin on asset
add the following packages just because they will be needed
ssh
vi
inetutil (contains telnet etc)
expect
add this nice little sc<x>ript to the root of the cygwin install
################################################
#!/usr/bin/expect
set name [lindex $argv 0]
spawn /usr/bin/telnet.exe $name
expect "Username:"
send "mradminr"
expect "Password:"
send "secretstuffr" # note the r means send carriage return
expect ">"
send "enabler"
expect "Password:"
send "moresecretstuffr"
#send "sh ver | inc up"
interact
###############################################
save as telex.sh or something
now create a bat to exe file with the following sc<x>ript
@echo off
d:Datacygwinbinexpect.exe d:Datacygwintelex.sh %1
rem the first part is to point to the expect.exe cygwin program the second part to the sc<x>ript file
rem save this sc<x>ript as c:windowssystem32telnet.com as when typing telnet blabla windows checks .com then .exe files
now when you goto cmd just type telnet (ip address) bingo your logged in.
#####################################
# example of working with hp switch.
set timeout 20
spawn ssh root@139.184.4.29
expect "assword:"
send "peekme\n"
send "show ip\n"
log_file -a hp.log
send "show ver\n"
send "exit\n"
send "exit\n"
send "y\n"
log_file ;# turn off logging
# read the log file
set fid [open hp.log r]
set contents [read -nonewline $fid]
close $fid
# remove the escape sequences
regsub -all {\033\[(?:\?|\d+;)?\d+[[:alpha:]]} $contents {} stripped
# write the new contents
set fid [open hp.log w]
puts $fid $stripped
close $fid
#############
##############################
get system info script
set timeout 20
spawn ssh tjb@139.184.4.29
expect "assword:"
send "Dek!\n"
expect "#"
log_file -noappend hp.log
send "show ip\n"
expect "#"
send "show run |inc on rel\r"
expect "#"
send "show syst\n"
expect "#"
send "show modules\n"
expect "#"
send "exit\n"
send "exit\n"
expect "?"
send "y\n"
interact
log_file ;# turn off logging
# read the log file
set fid [open hp.log r]
set contents [read -nonewline $fid]
close $fid
# remove the escape sequences
regsub -all {\033\[(?:\?|\d+;)?\d+[[:alpha:]]} $contents {} stripped
# write the new contents
set fid [open hp.log w]
puts $fid $stripped
close $fid
#################
bash script to extract the output
ip_add=$(cat hp.log |awk '/Bootp/ {print $4}')
mac_add=$(cat hp.log |awk '/Base/ {print $9}')
serial_add=$(cat hp.log |awk '/Serial/ {print $8}')
software_add=$(cat hp.log |awk '/Software/ {print $4}')
model_add=$(cat hp.log |awk '/release/ {print $7}')
echo ip is $ip_add
echo mac address is $mac_add
echo serial is $serial_add
echo software revision $software_add
echo model number is $model_add
~
######################
Script for tty grabs - annyoinly needs interact in the script to work - not very pretty but seems to work
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable name
set name [lindex $argv 0]
#Second argument is assigned to the variable user
set user [lindex $argv 1]
#Third argument is assigned to the variable password
set password [lindex $argv 2]
#This spawns the telnet program and connects it to the variable name
spawn tio -b 9600 -d 8 -f none -s 1 -p none /dev/ttyUSB0
send "connected\n"
log_file -noappend console.log
expect "#"
send "sh syst | inc MAC\n"
send " \n"
expect "#"
send "sh syst | inc Ser\n"
send " \n"
expect "#"
#The script expects login
#The script sends the user variable
#The script expects Password
#The script sends the password variable
#This hands control of the keyboard over to you (Nice expect feature!)
interact timeout 8 return
#sleep 10
#interact
log_file ;# turn off logging
# read the log file
set fid [open console.log r]
set contents [read -nonewline $fid]
close $fid
# remove the escape sequences
regsub -all {\033\[(?:\?|\d+;)?\d+[[:alpha:]]} $contents {} stripped
# write the new contents
set fid [open console.log w]
puts $fid $stripped
close $fid
tio -b 9600 -d 8 -f none -s 1 -p none -l --log-strip --log-file cap.log /dev/ttyUSB0
screen /dev/ttyUSB0
#!/usr/local/bin/basH
###########################################
# Router's IP address
#
IP_ADDRESS='172.3.65'
# Directory where the log files will be stored
#
DIR=/
########################################
if [ ! -e $DIR ]
then
mkdir $DIR
fi
# Tag specification: mmddhhmm
# DATE=`date +'%m%d'`
# TIME=`date +'%H%M'`
# while true; do
# TAG=$DATE$TIME
# Collect data from the router
#while true; do
DATE=`date +'%d-%m'`
TIME=`date +'%H%M'`
TAG=$DATE$TIME
sleep 10
(echo "m*4*";
sleep 6 ;
#echo "4o";
echo "en";
sleep 6;
echo "m*4*";
sleep 4
echo "wr net 172.24.1.138:/Firewall/NS-backup-`$DATE`"$DATE".Ciscoconfig";
echo "q";
sleep 3 )|telnet $IP_ADDRESS #> ASA.back
#done
#quit
sudo adduser admin
sudo grep -B1 -i '^%sudo' /etc/sudoers
adduser <UserNameHere> sudo
id <UserNameHere>
#!/bin/bash
# mini script to check if a user is a member of the pa group prior to undertaking any changes
clear
sleep 1
if [ -z "$1" ]; then
echo whoops - did you forget to add the username to the end of the command
exit 2
fi
iparesult=$(sudo ipa user-find $1 |grep -c login)
ldapresult=$(ldapsearch -x -D "CN=ldapbind,OU=Service Accounts,OU=US,DC=ad,DC=susx,DC=ac,DC=uk" -w notsecret -H ldap://ad.susx.ac.uk/ -b "OU=US,DC=ad,DC=susx,DC=ac,DC=uk" samaccountname=$1 |grep -c pa-extra)
if [ "$ldapresult" -gt 0 ]; then
echo user already a member of the LDAP - pa group
else
echo user not found to be in the LDAP - pa group
fi
if [ "$iparesult" -gt 0 ]; then
echo user already a member of the ipa users
exit 2
else
echo user not found to be in the ipa users
fi
netplan for corp auth with certificate
#start
network:
wifis:
wlan0:
dhcp4: yes
access-points:
"eduroam":
auth:
key-management: eap
method: peap
anonymous-identity: "user@sussex.ac.uk"
identity: "user@sussex.ac.uk"
password: "Deepprong"
ca-certificate: "/home/ubuntu/.cat_installer/ca.pem" # Created by the cat installer
#end
netplan for no auth wifi hotspot
#start
network:
ethernets:
eth0:
dhcp4: true
version: 2
wifis:
wlan0:
access-points:
wifi-m: {}
dhcp4: yes
#end
Handy one liners for AWK
Latest version of this file (in English) is usually at:
http://www.pement.org/awk/awk1line.txt
This file is also available in other languages:
Chinese - http://www.pement.org/awk/awk1line_zh-CN.txt
USAGE:
Unix: awk '/pattern/ {print "$1"}' # standard Unix shells
DOS/Win: awk '/pattern/ {print "$1"}' # compiled with DJGPP, Cygwin
awk "/pattern/ {print \"$1\"}" # GnuWin32, UnxUtils, Mingw
Notice to Windows users: The examples in this file use 'single quotes'
and are intended for use with a shell like bash or ksh. If you use a
command interpreter such as CMD.EXE or TCC.EXE, single quotes will not
work. You must use "double quotes" instead. Furthermore, Microsoft
Windows uses the percent sign (%) to mark environment variables, so
this symbol must be doubled (%%) to yield a single percent sign visible
to awk compiled for Windows or MS-DOS. (Again, this warning does not
apply if your shell is bash, ksh, or a standard Unix shell.)
I learned awk in a DOS environment, so some of the notes warn of DOS
and Unix newline issues. "\n" represents a newline (LF) in awk.
There are 4 versions of awk in common use: original awk (1977), new awk
or nawk (1985), mawk (a variant of new awk), and GNU awk or gawk (still
actively maintained). These scripts will run under nawk, the most common
version in the Unix world.
If an example runs only on GNU awk, the command 'gawk' will be used. I
consider a one-line script to be 65 characters or less. Shorter scripts
usually appear first. Finally, I normally use '1' instead of '{print}'
to print a line of output. Let me know of any errors you find.
FILE SPACING:
# double space a file
awk '1;{print ""}'
awk 'BEGIN{ORS="\n\n"};1'
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
# NOTE: On Unix systems, DOS lines which have only CRLF (\r\n) are
# often treated as non-blank, and thus 'NF' alone will return TRUE.
awk 'NF{print $0 "\n"}'
# triple space a file
awk '1;{print "\n"}'
NUMBERING AND CALCULATIONS:
# precede each line by its line number FOR THAT FILE (left alignment).
# Using a tab (\t) instead of space will preserve margins.
awk '{print FNR "\t" $0}' files*
# precede each line by its line number FOR ALL FILES TOGETHER, with tab.
awk '{print NR "\t" $0}' files*
# number each line of a file (number on left, right-aligned)
# Double the percent signs if typing from the DOS command prompt.
awk '{printf("%5d : %s\n", NR,$0)}'
# number each line of file, but only print numbers if line is not blank
# Remember caveats about Unix treatment of \r (mentioned above)
awk 'NF{$0=++a " :" $0};1'
awk '{print (NF? ++a " :" :"") $0}'
# count lines (emulates "wc -l")
awk 'END{print NR}'
# print the sums of the fields of every line
awk '{s=0; for (i=1; i<=NF; i++) s=s+$i; print s}'
# add all fields in all lines and print the sum
awk '{for (i=1; i<=NF; i++) s=s+$i}; END{print s}'
# print every line after replacing each field with its absolute value
awk '{for (i=1; i<=NF; i++) if ($i < 0) $i = -$i; print }'
awk '{for (i=1; i<=NF; i++) $i = ($i < 0) ? -$i : $i; print }'
# print the total number of fields ("words") in all lines
awk '{ total = total + NF }; END {print total}' file
# print the total number of lines that contain "Beth"
awk '/Beth/{n++}; END {print n+0}' file
# print the largest first field and the line that contains it
# Intended for finding the longest string in field #1
awk '$1 > max {max=$1; maxline=$0}; END{ print max, maxline}'
# print the number of fields in each line, followed by the line
awk '{ print NF ":" $0 } '
# print the last field of each line
awk '{ print $NF }'
# print the last field of the last line
awk '{ field = $NF }; END{ print field }'
# print every line with more than 4 fields
awk 'NF > 4'
# print every line where the value of the last field is > 4
awk '$NF > 4'
STRING CREATION:
# create a string of a specific length (e.g., generate 513 spaces)
awk 'BEGIN{while (a++<513) s=s " "; print s}'
# insert a string of specific length at a certain character position
# Example: insert 49 spaces after column #6 of each input line.
gawk --re-interval 'BEGIN{while(a++<49)s=s " "};{sub(/^.{6}/,"&" s)};1'
ARRAY CREATION:
# These next 2 entries are not one-line scripts, but the technique
# is so handy that it merits inclusion here.
# create an array named "month", indexed by numbers, so that month[1]
# is 'Jan', month[2] is 'Feb', month[3] is 'Mar' and so on.
split("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec", month, " ")
# create an array named "mdigit", indexed by strings, so that
# mdigit["Jan"] is 1, mdigit["Feb"] is 2, etc. Requires "month" array
for (i=1; i<=12; i++) mdigit[month[i]] = i
TEXT CONVERSION AND SUBSTITUTION:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
awk '{sub(/\r$/,"")};1' # assumes EACH line ends with Ctrl-M
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format
awk '{sub(/$/,"\r")};1'
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format
awk 1
# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
# Cannot be done with DOS versions of awk, other than gawk:
gawk -v BINMODE="w" '1' infile >outfile
# Use "tr" instead.
tr -d \r <infile >outfile # GNU tr version 1.22 or higher
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
awk '{sub(/^[ \t]+/, "")};1'
# delete trailing whitespace (spaces, tabs) from end of each line
awk '{sub(/[ \t]+$/, "")};1'
# delete BOTH leading and trailing whitespace from each line
awk '{gsub(/^[ \t]+|[ \t]+$/,"")};1'
awk '{$1=$1};1' # also removes extra space between fields
# insert 5 blank spaces at beginning of each line (make page offset)
awk '{sub(/^/, " ")};1'
# align all text flush right on a 79-column width
awk '{printf "%79s\n", $0}' file*
# center all text on a 79-character width
awk '{l=length();s=int((79-l)/2); printf "%"(s+l)"s\n",$0}' file*
# substitute (find and replace) "foo" with "bar" on each line
awk '{sub(/foo/,"bar")}; 1' # replace only 1st instance
gawk '{$0=gensub(/foo/,"bar",4)}; 1' # replace only 4th instance
awk '{gsub(/foo/,"bar")}; 1' # replace ALL instances in a line
# substitute "foo" with "bar" ONLY for lines which contain "baz"
awk '/baz/{gsub(/foo/, "bar")}; 1'
# substitute "foo" with "bar" EXCEPT for lines which contain "baz"
awk '!/baz/{gsub(/foo/, "bar")}; 1'
# change "scarlet" or "ruby" or "puce" to "red"
awk '{gsub(/scarlet|ruby|puce/, "red")}; 1'
# reverse order of lines (emulates "tac")
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' file*
# if a line ends with a backslash, append the next line to it (fails if
# there are multiple lines ending with backslash...)
awk '/\\$/ {sub(/\\$/,""); getline t; print $0 t; next}; 1' file*
# print and sort the login names of all users
awk -F ":" '{print $1 | "sort" }' /etc/passwd
# print the first 2 fields, in opposite order, of every line
awk '{print $2, $1}' file
# switch the first 2 fields of every line
awk '{temp = $1; $1 = $2; $2 = temp}' file
# print every line, deleting the second field of that line
awk '{ $2 = ""; print }'
# print in reverse order the fields of every line
awk '{for (i=NF; i>0; i--) printf("%s ",$i);print ""}' file
# concatenate every 5 lines of input, using a comma separator
# between fields
awk 'ORS=NR%5?",":"\n"' file
SELECTIVE PRINTING OF CERTAIN LINES:
# print first 10 lines of file (emulates behavior of "head")
awk 'NR < 11'
# print first line of file (emulates "head -1")
awk 'NR>1{exit};1'
# print the last 2 lines of a file (emulates "tail -2")
awk '{y=x "\n" $0; x=$0};END{print y}'
# print the last line of a file (emulates "tail -1")
awk 'END{print}'
# print only lines which match regular expression (emulates "grep")
awk '/regex/'
# print only lines which do NOT match regex (emulates "grep -v")
awk '!/regex/'
# print any line where field #5 is equal to "abc123"
awk '$5 == "abc123"'
# print only those lines where field #5 is NOT equal to "abc123"
# This will also print lines which have less than 5 fields.
awk '$5 != "abc123"'
awk '!($5 == "abc123")'
# matching a field against a regular expression
awk '$7 ~ /^[a-f]/' # print line if field #7 matches regex
awk '$7 !~ /^[a-f]/' # print line if field #7 does NOT match regex
# print the line immediately before a regex, but not the line
# containing the regex
awk '/regex/{print x};{x=$0}'
awk '/regex/{print (NR==1 ? "match on line 1" : x)};{x=$0}'
# print the line immediately after a regex, but not the line
# containing the regex
awk '/regex/{getline;print}'
# grep for AAA and BBB and CCC (in any order on the same line)
awk '/AAA/ && /BBB/ && /CCC/'
# grep for AAA and BBB and CCC (in that order)
awk '/AAA.*BBB.*CCC/'
# print only lines of 65 characters or longer
awk 'length > 64'
# print only lines of less than 65 characters
awk 'length < 64'
# print section of file from regular expression to end of file
awk '/regex/,0'
awk '/regex/,EOF'
# print section of file based on line numbers (lines 8-12, inclusive)
awk 'NR==8,NR==12'
# print line number 52
awk 'NR==52'
awk 'NR==52 {print;exit}' # more efficient on large files
# print section of file between two regular expressions (inclusive)
awk '/Iowa/,/Montana/' # case sensitive
SELECTIVE DELETION OF CERTAIN LINES:
# delete ALL blank lines from a file (same as "grep '.' ")
awk NF
awk '/./'
# remove duplicate, consecutive lines (emulates "uniq")
awk 'a !~ $0; {a=$0}'
# remove duplicate, nonconsecutive lines
awk '!a[$0]++' # most concise script
awk '!($0 in a){a[$0];print}' # most efficient script
CREDITS AND THANKS:
Special thanks to the late Peter S. Tillier (U.K.) for helping me with
the first release of this file, and to Daniel Jana, Yisu Dong, and
others for their suggestions and corrections.
The golden reference is "The AWK Programming Language" (1988) by Alfred
Aho, Peter Weinberger, and Brian Kernighan, the creators of awk. (The
name AWK comes from the first initial of each of their names.)
For additional syntax instructions, including the way to apply editing
commands from a disk file instead of the command line, consult:
"sed & awk, 2nd Edition," by Dale Dougherty and Arnold Robbins
(O'Reilly, 1997)
"UNIX Text Processing," by Dale Dougherty and Tim O'Reilly (Hayden
Books, 1987)
"GAWK: Effective awk Programming," by Arnold D. Robbins (O'Reilly)
or at http://www.gnu.org/software/gawk/manual/
To fully exploit the power of awk, one must know regular expressions.
For a detailed study, see "Mastering Regular Expressions, 3d edition"
by Jeffrey Friedl (O'Reilly, 2006).
The info and manual ("man") pages on Unix systems may be helpful (try
"man awk", "man nawk", "man gawk", "man regexp", or the section on
regular expressions in "man ed").
USE OF '\t' IN awk SCRIPTS: For clarity in documentation, I have used
'\t' to indicate a tab character (0x09) in the scripts. All versions of
awk should recognize this abbreviation.
#---end of file---
HANDY ONE-LINERS FOR SED (Unix stream editor) Mar. 23, 2001
compiled by Eric Pement <pemente@northpark.edu> version 5.1
Latest version of this file is usually at:
http://www.student.northpark.edu/pemente/sed/sed1line.txt
http://www.cornerstonemag.com/sed/sed1line.txt
This file is also available in Portuguese at:
http://www.lrv.ufsc.br/wmaker/sed_ptBR.html
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
sed 'G;G'
# undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
NUMBERING:
# number each line of a file (simple left alignment). Using a tab (see
# note on '\t' at end of file) instead of space will preserve margins.
sed = filename | sed 'N;s/\n/\t/'
# number each line of a file (number on left, right-aligned)
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
# number each line of file, but only print numbers if line is not blank
sed '/./=' filename | sed '/./N; s/\n/ /'
# count lines (emulates "wc -l")
sed -n '$='
TEXT CONVERSION AND SUBSTITUTION:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # gsed 3.02.80, but top script is easier
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format
sed "s/$/`echo -e \\\r`/" # command line under ksh
sed 's/$'"/`echo \\\r`/" # command line under bash
sed "s/$/`echo \\\r`/" # command line under zsh
sed 's/$/\r/' # gsed 3.02.80
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format
sed "s/$//" # method 1
sed -n p # method 2
# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
# Cannot be done with DOS versions of sed. Use "tr" instead.
tr -d \r <infile >outfile # GNU tr version 1.22 or higher
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
sed 's/^[ \t]*//' # see note on '\t' at end of file
# delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' # see note on '\t' at end of file
# delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
# insert 5 blank spaces at beginning of each line (make page offset)
sed 's/^/ /'
# align all text flush right on a 79-column width
sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at 78 plus 1 space
# center all text in the middle of 79-column width. In method 1,
# spaces at the beginning of the line are significant, and trailing
# spaces are appended at the end of the line. In method 2, spaces at
# the beginning of the line are discarded in centering the line, and
# no trailing spaces appear at the end of lines.
sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' # method 2
# substitute (find and replace) "foo" with "bar" on each line
sed 's/foo/bar/' # replaces only 1st instance in a line
sed 's/foo/bar/4' # replaces only 4th instance in a line
sed 's/foo/bar/g' # replaces ALL instances in a line
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
sed 's/\(.*\)foo/\1bar/' # replace only the last case
# substitute "foo" with "bar" ONLY for lines which contain "baz"
sed '/baz/s/foo/bar/g'
# substitute "foo" with "bar" EXCEPT for lines which contain "baz"
sed '/baz/!s/foo/bar/g'
# change "scarlet" or "ruby" or "puce" to "red"
sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g' # most seds
gsed 's/scarlet\|ruby\|puce/red/g' # GNU sed only
# reverse order of lines (emulates "tac")
# bug/feature in HHsed v1.5 causes blank lines to be deleted
sed '1!G;h;$!d' # method 1
sed -n '1!G;h;$p' # method 2
# reverse each character on the line (emulates "rev")
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
# join pairs of lines side-by-side (like "paste")
sed '$!N;s/\n/ /'
# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'
# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
# add commas to numeric strings, changing "1234567" to "1,234,567"
gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta' # GNU sed
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' # other seds
# add commas to numbers with decimal points and minus signs (GNU sed)
gsed ':a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta'
# add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
gsed '0~5G' # GNU sed only
sed 'n;n;n;n;G;' # other seds
SELECTIVE PRINTING OF CERTAIN LINES:
# print first 10 lines of file (emulates behavior of "head")
sed 10q
# print first line of file (emulates "head -1")
sed q
# print the last 10 lines of a file (emulates "tail")
sed -e :a -e '$q;N;11,$D;ba'
# print the last 2 lines of a file (emulates "tail -2")
sed '$!N;$!D'
# print the last line of a file (emulates "tail -1")
sed '$!d' # method 1
sed -n '$p' # method 2
# print only lines which match regular expression (emulates "grep")
sed -n '/regexp/p' # method 1
sed '/regexp/!d' # method 2
# print only lines which do NOT match regexp (emulates "grep -v")
sed -n '/regexp/!p' # method 1, corresponds to above
sed '/regexp/d' # method 2, simpler syntax
# print the line immediately before a regexp, but not the line
# containing the regexp
sed -n '/regexp/{g;1!p;};h'
# print the line immediately after a regexp, but not the line
# containing the regexp
sed -n '/regexp/{n;p;}'
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
# grep for AAA and BBB and CCC (in any order)
sed '/AAA/!d; /BBB/!d; /CCC/!d'
# grep for AAA and BBB and CCC (in that order)
sed '/AAA.*BBB.*CCC/!d'
# grep for AAA or BBB or CCC (emulates "egrep")
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d # most seds
gsed '/AAA\|BBB\|CCC/!d' # GNU sed only
# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
# print paragraph if it contains AAA and BBB and CCC (in any order)
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
# print paragraph if it contains AAA or BBB or CCC
sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only
# print only lines of 65 characters or longer
sed -n '/^.\{65\}/p'
# print only lines of less than 65 characters
sed -n '/^.\{65\}/!p' # method 1, corresponds to above
sed '/^.\{65\}/d' # method 2, simpler syntax
# print section of file from regular expression to end of file
sed -n '/regexp/,$p'
# print section of file based on line numbers (lines 8-12, inclusive)
sed -n '8,12p' # method 1
sed '8,12!d' # method 2
# print line number 52
sed -n '52p' # method 1
sed '52!d' # method 2
sed '52q;d' # method 3, efficient on large files
# beginning at line 3, print every 7th line
gsed -n '3~7p' # GNU sed only
sed -n '3,${p;n;n;n;n;n;n;}' # other seds
# print section of file between two regular expressions (inclusive)
sed -n '/Iowa/,/Montana/p' # case sensitive
SELECTIVE DELETION OF CERTAIN LINES:
# print all of file EXCEPT section between 2 regular expressions
sed '/Iowa/,/Montana/d'
# delete duplicate, consecutive lines from a file (emulates "uniq").
# First line in a set of duplicate lines is kept, rest are deleted.
sed '$!N; /^\(.*\)\n\1$/!P; D'
# delete duplicate, nonconsecutive lines from a file. Beware not to
# overflow the buffer size of the hold space, or else use GNU sed.
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
# delete the first 10 lines of a file
sed '1,10d'
# delete the last line of a file
sed '$d'
# delete the last 2 lines of a file
sed 'N;$!P;$!D;$d'
# delete the last 10 lines of a file
sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2
# delete every 8th line
gsed '0~8d' # GNU sed only
sed 'n;n;n;n;n;n;n;d;' # other seds
# delete ALL blank lines from a file (same as "grep '.' ")
sed '/^$/d' # method 1
sed '/./!d' # method 2
# delete all CONSECUTIVE blank lines from file except the first; also
# deletes all blank lines from top and end of file (emulates "cat -s")
sed '/./,/^$/!d' # method 1, allows 0 blanks at top, 1 at EOF
sed '/^$/N;/\n$/D' # method 2, allows 1 blank at top, 0 at EOF
# delete all CONSECUTIVE blank lines from file except the first 2:
sed '/^$/N;/\n$/N;//D'
# delete all leading blank lines at top of file
sed '/./,$!d'
# delete all trailing blank lines at end of file
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' # works on all seds
sed -e :a -e '/^\n*$/N;/\n$/ba' # ditto, except for gsed 3.02*
# delete the last line of each paragraph
sed -n '/^$/{p;h;};/./{x;/./p;}'
SPECIAL APPLICATIONS:
# remove nroff overstrikes (char, backspace) from man pages. The 'echo'
# command may need an -e switch if you use Unix System V or bash shell.
sed "s/.`echo \\\b`//g" # double quotes required for Unix environment
sed 's/.^H//g' # in bash/tcsh, press Ctrl-V and then Ctrl-H
sed 's/.\x08//g' # hex expression for sed v1.5
# get Usenet/e-mail message header
sed '/^$/q' # deletes everything after first blank line
# get Usenet/e-mail message body
sed '1,/^$/d' # deletes everything up to first blank line
# get Subject header, but remove initial "Subject: " portion
sed '/^Subject: */!d; s///;q'
# get return address header
sed '/^Reply-To:/q; /^From:/h; /./d;g;q'
# parse out the address proper. Pulls out the e-mail address by itself
# from the 1-line return address header (see preceding script)
sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//'
# add a leading angle bracket and space to each line (quote a message)
sed 's/^/> /'
# delete leading angle bracket & space from each line (unquote a message)
sed 's/^> //'
# remove most HTML tags (accommodates multiple-line tags)
sed -e :a -e 's/<[^>]*>//g;/</N;//ba'
# extract multi-part uuencoded binaries, removing extraneous header
# info, so that only the uuencoded portion remains. Files passed to
# sed must be passed in the proper order. Version 1 can be entered
# from the command line; version 2 can be made into an executable
# Unix shell script. (Modified from a script by Rahul Dhesi.)
sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode # vers. 1
sed '/^end/,/^begin/d' "$@" | uudecode # vers. 2
# zip up each .TXT file individually, deleting the source file and
# setting the name of each .ZIP file to the basename of the .TXT file
# (under DOS: the "dir /b" switch returns bare filenames in all caps).
echo @echo off >zipup.bat
dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat
TYPICAL USE: Sed takes one or more editing commands and applies all of
them, in sequence, to each line of input. After all the commands have
been applied to the first input line, that line is output and a second
input line is taken for processing, and the cycle repeats. The
preceding examples assume that input comes from the standard input
device (i.e, the console, normally this will be piped input). One or
more filenames can be appended to the command line if the input does
not come from stdin. Output is sent to stdout (the screen). Thus:
cat filename | sed '10q' # uses piped input
sed '10q' filename # same effect, avoids a useless "cat"
sed '10q' filename > newfile # redirects output to disk
For additional syntax instructions, including the way to apply editing
commands from a disk file instead of the command line, consult "sed &
awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly,
1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty
and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst
distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power
of sed, one must understand "regular expressions." For this, see
"Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997).
The manual ("man") pages on Unix systems may be helpful (try "man
sed", "man regexp", or the subsection on regular expressions in "man
ed"), but man pages are notoriously difficult. They are not written to
teach sed use or regexps to first-time users, but as a reference text
for those already acquainted with these tools.
QUOTING SYNTAX: The preceding examples use single quotes ('...')
instead of double quotes ("...") to enclose editing commands, since
sed is typically used on a Unix platform. Single quotes prevent the
Unix shell from intrepreting the dollar sign ($) and backquotes
(`...`), which are expanded by the shell if they are enclosed in
double quotes. Users of the "csh" shell and derivatives will also need
to quote the exclamation mark (!) with the backslash (i.e., \!) to
properly run the examples listed above, even within single quotes.
Versions of sed written for DOS invariably require double quotes
("...") instead of single quotes to enclose editing commands.
USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
the expression '\t' to indicate a tab character (0x09) in the scripts.
However, most versions of sed do not recognize the '\t' abbreviation,
so when typing these scripts from the command line, you should press
the TAB key instead. '\t' is supported as a regular expression
metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.
VERSIONS OF SED: Versions of sed do differ, and some slight syntax
variation is to be expected. In particular, most do not support the
use of labels (:name) or branch instructions (b,t) within editing
commands, except at the end of those commands. We have used the syntax
which will be portable to most users of sed, even though the popular
GNU versions of sed allow a more succinct syntax. When the reader sees
a fairly long command such as this:
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
it is heartening to know that GNU sed will let you reduce it to:
sed '/AAA/b;/BBB/b;/CCC/b;d' # or even
sed '/AAA\|BBB\|CCC/b;d'
In addition, remember that while many versions of sed accept a command
like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which
contains space before the 's'. Omit the space when typing the command.
OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to
large input files or slow processors or hard disks), substitution will
be executed more quickly if the "find" expression is specified before
giving the "s/.../.../" instruction. Thus:
sed 's/foo/bar/g' filename # standard replace command
sed '/foo/ s/foo/bar/g' filename # executes more quickly
sed '/foo/ s//bar/g' filename # shorthand sed syntax
On line selection or deletion in which you only need to output lines
from the first part of the file, a "quit" command (q) in the script
will drastically reduce processing time for large files. Thus:
sed -n '45,50p' filename # print line nos. 45-50 of a file
sed -n '51q;45,50p' filename # same, but executes much faster
If you have any additional scripts to contribute or if you find errors
in this document, please send e-mail to the compiler. Indicate the
version of sed you used, the operating system it was compiled for, and
the nature of the problem. Various scripts in this file were written
or contributed by:
Al Aab <af137@freenet.toronto.on.ca> # "seders" list moderator
Edgar Allen <era@sky.net> # various
Yiorgos Adamopoulos <adamo@softlab.ece.ntua.gr>
Dale Dougherty <dale@songline.com> # author of "sed & awk"
Carlos Duarte <cdua@algos.inesc.pt> # author of "do it with sed"
Eric Pement <pemente@northpark.edu> # author of this document
Ken Pizzini <ken@halcyon.com> # author of GNU sed v3.02
S.G. Ravenhall <stew.ravenhall@totalise.co.uk> # great de-html script
Greg Ubben <gsu@romulus.ncsc.mil> # many contributions & much help
tpl@eng.cam.ac.uk
grab a copy of jessie with already compiled version of lldpad here : https://drive.google.com/file/d/1t5is4M9He7bc0JvprCYJ2bLBi5f4VA-B/view?usp=sharing
create a bootable sdcard that has jessie on it, then replace with this image through the use of dd
dd command will be similar to : dd if=c:\Users\Terry\rp-lldp-v7.img bs=1M of=\\?\Device\HarddiskVolume25 --size --progress
you are seeking to write this to the larger part of the sdcard where the os would sit.
under the user login .profile on the newly built sd card add the following lines
sudo setterm -powersave off -blank 0
bash script.sh
########### script.sh ##################
while [ 123 ]
rm -rf result.txt
do
clear
ifconfig eth0
echo "reporting findings"
date > result.txt
sudo lldptool -t -n -i eth0 >> result.txt
grep -E 'UTC|IP|PVID|Local' result.txt
echo "waiting for detection"
sleep 9
done
################################
Usermod -g groupname username
usermod -a -G examplegroup exampleusername
Is there a way that i can remove the Language Menu from the live disto , it shows a 100 languages but i want it to show just a few or none. ? to mount a squashfs - mount myfiles.sqsh /mnt/mydir -t squashfs -o loop
mksquash /location/to/sou-1 rce /location/to/destination.sfs Trying to create an encrypted location to boot a memory stick or better still a cd. http://www.saout.de/tikiwiki/tiki-index.php?page=USBFlashMedia
http://martin.elwin.com/blog/tag/squashfs/
http://www.howtoforge.com/ubuntu_dm_crypt_luks
http://narnia.cs.ttu.edu/drupal/node/102
http://martin.elwin.com/blog/2008/05/backups-with-squashfs-and-luks/ a useful (file / Folder) encryption not block level encryption is encfs
install the attached packages into ubuntu 8.10 and from the command line do as follows
sudo modprobe fuse = loads the fuse app into the kernel
sudo adduser <your login username> fuse = add yourself to the fuse group
encfs /encrypted /visible = this will create the encrypted folder and the clear folder.
at this point you will be prompted for encryption methods passwords, all that good stuff
once done you can just add files to the folder visible and your see an encrypted one in the folder /encrypted
fusermount u ~/visible = unmounts the encrypted folder
encfs /encrypted /visible = to remount your be prompted for the password. once the encrypted file is created you can mksquash this structure which remains encrypted.
you can then mount the squashfs by doing the following : mount /src.sfs /dest -t squashfs -o loop
then run : encfs /dest /visible
enter your password and the files are visible.
question is can this be prompted at time of booting ? How do I mount the ubuntu initrd?
They are gzip'ed cpio archives:
Code:
mkdir tmp
cd tmp
gzip -dc /somepath/initrd.gz | cpio -id
# do the edits on the files
find . | cpio --quiet --dereference -o -H newc | gzip -9 > /somepath/new-initrd.gz encfs
encfs /media/usb /home/pc
this will create a folder on your usb stick that will contain the encrypted files, the source of files are in /home/pc
once you have gone through the prompts
enter the above command again , enter your password
then place files in /home/pc and see the encrypted files on your /media/usb
to install the above do the following
sudo apt-get install encfs fuse -utils
sudo modprobe fuse
sudo adduser <your username> fuse http://www.linux.com/archive/feature/52820 http://www.ibm.com/developerworks/linux/library/l-initrd.html
http://www.bauer-power.net/2007/07/how-to-fully-encrypt-your-ubuntu.html
http://busybox.net/products.html
http://www.hermann-uwe.de/blog/howto-disk-encryption-with-dm-crypt-luks-and-debian usb-creator = create bootable usb from cdrom this file contains the vmlinuz and initrd.gz that will use the luks file structure.
however its not working as it complains when trying to load the modprobe (devices)
the closest config to have it working so far. dd if=/dev/urandom" of=filesystem bs=1M count=550
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksFormat -c "aes-cbc-essiv:sha256" /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 luksloop
sudo mkfs.ext3 /dev/mapper/luksloop
sudo mkdir /mnt/cryptfs
sudo mount /dev/mapper/luksloop /mnt/cryptfs
sudo cp filesystem.squashfs /mnt/cryptfs
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/ma-1 pper/luksloop
sudo losetup -d /dev/loop0
mv filesystem filesystem.squashfs http://ardchoille42.blogspot.com/2009/09/how-to-use-screensaver-as-desktop.html creation of the encrypted volume notes
--------------------------------------
dd if=/dev/urandom" o45 f=filesystem bs=1M count=550
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksFormat -c "aes-cbc-essiv:sha256" /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 luksloop
sudo mkfs.ext3 /dev/mapper/luksloop
sudo mkdir /mnt/cryptfs
sudo mount /dev/mapper/luksloop /mnt/cryptfs
sudo cp filesystem.squashfs /mnt/cryptfs
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/mapper/luksloop
sudo losetup -d /dev/loop0
mv filesystem filesystem.squashfs
adding a certificate to the client
----------------------------------
from the desktop xterm and goto /etc/opt/cisco-vpnclient/Profiles/
first of all you need to remove any existing certificates cisco_cert_mgr -U -op delete
then pick the installed certs to remove in prep for issuing the new cert.
then run the following bash enroll my_username
follow the prompts
grant the cert from svr-ca-1
once complete you need to mksquash the files created.
creating the squashfs image to put in the encrypted volume
--------------------------------------------------------
mount the encrypted volume from above
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksOpen /dev/loop0 luksloop
enter your certificate password
sudo mkdir /mnt/encvol
sudo mount /dev/mapper/luksloop /mnt/encvol
mksquashfs /etc/opt/ /cisco.sfs
mkdir /mnt/sfs
mount -t squashfs /cisco.sfs /mnt/sfs -o loop
cd /mnt
check there is a folder there called cisco-vpnclient
then cd /
umount /mnt
cp /cisco.sfs to the mounted location of the encrypted volume "/mnt/sfs"
then unmount the encrypted volume.
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/mapper/luksloop
sudo losetup -d /dev/loop0
note loop0 might have already been used in which case use another number 4,5 should be free
all going well you now have a 2048Mbit file called cisco.sfs
this needs to be placed into the casper directory on the cd your going to burn, copy this to a memory stick.
a-1 nd drop it onto the iso image in windows. attached is a zip that will pull and install everything required a few command tools to squashfs and unsquash linux file systems from windows wget http://www.url.com/car-salvage-auctions/15028826
sleep 1
cat index.html | grep bid_amount_0 |68 awk 'BEGIN { FS = ">£" } ; { print " 15028826 - Current Bid: £",$2 }' | sed -e 's/.......$//' -1 >> listing.txt
rm -rf index.html gconf-editor
Then, go to Apps > Nautilus > Preferences > Always_Use_Location_Entry
see attachment attached is the toshiba bios flash iso
just insert boot from cdrom and it will check your system matches the bios proposed and flash version 2.10
known to fix ubuntu 11.04 booting / hanging at networking or audio loading.
wget http://www.url.com/car-salvage-auctions/15028826
sleep 1
cat index.html | grep bid_amount_0 | awk 'BEGIN { FS = ">£" } ; { print " 15028826 - Current Bid: £",$2 }' | sed -e 's/.......$//' >> listing.txt
rm -rf index.html
to mount a squashfs - mount myfiles.sqsh /mnt/mydir -t squashfs -o loop
mksquash /location/to/source /location/to/destination.sfs
###############################
a useful (file / Folder) encryption not block level encryption is encfs
install the attached packages into ubuntu 8.10 and from the command line do as follows
sudo modprobe fuse = loads the fuse app into the kernel
sudo adduser <your login username> fuse = add yourself to the fuse group
encfs /encrypted /visible = this will create the encrypted folder and the clear folder.
at this point you will be prompted for encryption methods passwords, all that good stuff
once done you can just add files to the folder visible and your see an encrypted one in the folder /encrypted
fusermount -u ~/visible = unmounts the encrypted folder
encfs /encrypted /visible = to remount your be prompted for the password.
#########################################
once the encrypted file is created you can mksquash this structure which remains encrypted.
you can then mount the squashfs by doing the following : mount /src.sfs /dest -t squashfs -o loop
then run : encfs /dest /visible
enter your password and the files are visible.
question is can this be prompted at time of booting ?
############################################
How do I mount the ubuntu initrd?
They are gzip'ed cpio archives:
Code:
mkdir tmp
cd tmp
gzip -dc /somepath/initrd.gz | cpio -id
# do the edits on the files
find . | cpio --quiet --dereference -o -H newc | gzip -9 > /somepath/new-initrd.gz
###############################################
encfs
encfs /media/usb /home/pc
this will create a folder on your usb stick that will contain the encrypted files, the source of files are in /home/pc
once you have gone through the prompts
enter the above command again , enter your password
then place files in /home/pc and see the encrypted files on your /media/usb
to install the above do the following
sudo apt-get install encfs fuse-utils
sudo modprobe fuse
sudo adduser <your username> fuse
############################################
usb-creator = create bootable usb from cdrom
this file contains the vmlinuz and initrd.gz that will use the luks file structure.
however its not working as it complains when trying to load the modprobe (devices)
the closest config to hav it working so far.
dd if=/dev/urandom" of=filesystem bs=1M count=550
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksFormat -c "aes-cbc-essiv:sha256" /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 luksloop
sudo mkfs.ext3 /dev/mapper/luksloop
sudo mkdir /mnt/cryptfs
sudo mount /dev/mapper/luksloop /mnt/cryptfs
sudo cp filesystem.squashfs /mnt/cryptfs
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/mapper/luksloop
sudo losetup -d /dev/loop0
mv filesystem filesystem.squashfs
#####################################
creation of the encrypted volume notes
--------------------------------------
dd if=/dev/urandom" of=filesystem bs=1M count=550
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksFormat -c "aes-cbc-essiv:sha256" /dev/loop0
sudo cryptsetup luksOpen /dev/loop0 luksloop
sudo mkfs.ext3 /dev/mapper/luksloop
sudo mkdir /mnt/cryptfs
sudo mount /dev/mapper/luksloop /mnt/cryptfs
sudo cp filesystem.squashfs /mnt/cryptfs
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/mapper/luksloop
sudo losetup -d /dev/loop0
mv filesystem filesystem.squashfs
adding a certificate to the client
----------------------------------
from the desktop xterm and goto /etc/opt/cisco-vpnclient/Profiles/
first of all you need to remove any existing certificates cisco_cert_mgr -U -op delete
then pick the installed certs to remove in prep for issuing the new cert.
then run the following bash enroll my_username
follow the prompts
grant the cert from svr-ca-1
once complete you need to mksquash the files created.
creating the squashfs image to put in the encrypted volume
----------------------------------------------------------
mount the encrypted volume from above
sudo losetup /dev/loop0 filesystem
sudo cryptsetup luksOpen /dev/loop0 luksloop
enter your certificate password
sudo mkdir /mnt/encvol
sudo mount /dev/mapper/luksloop /mnt/encvol
mksquashfs /etc/opt/ /cisco.sfs
mkdir /mnt/sfs
mount -t squashfs /cisco.sfs /mnt/sfs -o loop
cd /mnt
check there is a folder there called cisco-vpnclient
then cd /
umount /mnt
cp /cisco.sfs to the mounted location of the encrypted volume "/mnt/sfs"
then unmount the encrypted volume.
sudo umount /mnt/cryptfs
sudo cryptsetup luksClose /dev/mapper/luksloop
sudo losetup -d /dev/loop0
note loop0 might have already been used in which case use another number 4,5 should be free
all going well you now have a 2048Mbit file called cisco.sfs
this needs to be placed into the casper directory on the cd your going to burn, copy this to a memory stick.
and drop it onto the iso image in windows.
#######################################
#!/bin/bash
# 7 days in seconds
if [ -z "$1" ] && [ -z "$2" ]
then
echo whoops you forgot to add some commands
echo add the domain and number of days remaining to check
echo e.g. ssl-checker.sh google.co.uk 600
exit 0
fi
NUMOFDAYSWARN=$2
ADAY="86400" #inseconds
let DAYS=$NUMOFDAYSWARN*$ADAY
echo $DAYS
DOM=$1
PORT="443"
## note echo added ##
echo | openssl s_client -servername $DOM -connect $DOM:$PORT \
| openssl x509 -enddate -noout -checkend "$DAYS" |grep -q 'Certificate will expire'
if [ $? -eq 0 ]
then
echo Certificate warning for $DOM less than $2 days remain
else
echo no cert warning
fi
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# https://www.nginx.com/resources/wiki/start/
# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
# https://wiki.debian.org/Nginx/DirectoryStructure
#
# In most cases, administrators will remove this file from sites-enabled/ and
# leave it as reference inside of sites-available where it will continue to be
# updated by the nginx packaging team.
#
# This file will automatically load configuration files provided by other
# applications, such as Drupal or Wordpress. These applications will be made
# available underneath a path with that package name, such as /drupal8.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##
# Default server configuration
#
# server {
# listen 88;
# root /var/www/html/bubble;
# }
# Set $bubble based on user string. This could be improved by setting bubble to the uri of the page the client should
# be looking at e.g. default /index.html; others (defined as a regex (don't forget the ~) bubble.html;)
map $http_user_agent $bubble {
~^.*Macintosh((?!Version|Safari).)*$ 1;
~Build|npbot|malicious 1;
default 0;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
# SSL configuration
#
listen 443 ssl default_server;
ssl_certificate /etc/ssl/private/quarantine.sussex.ac.uk.pem;
ssl_certificate_key /etc/ssl/private/quarantine.sussex.ac.uk.key;
ssl_password_file /etc/nginx/ssl_pass.txt;
# listen [::]:443 ssl default_server;
#
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
# If bubble is set then redirect to the 'bubble' pages telling users to close the CNA and open a full browser.
if ($bubble) {
rewrite ^ /bubble/index.html break;
}
location / {
# If above rewrite turns out to redirect all requests coming from a client to bubble page then try
# https://stackoverflow.com/questions/45045665/nginx-using-or-set-at-regex-for-the-map
# i.e. get the map function to set the page the client should be looking at based on
# the user agent string and then echo it out as below
# echo $bubble
# Failing that, I wonder if seting $uri to the vaule of bubble as above would work (rather than redirecting)
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
# location /installers/ {
# default_type application/octet-steam;
# }
# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
# LINE ADDED 30-08-2022 to test for user agent
#**********************************************************
# if ($http_user_agent ~ ^.*Macintosh((?!Version|Safari).)*$) {
# #return 301 http://172.16.75.196:12345;
# return 301 http://172.16.1.26;
# }
# if ($http_user_agent ~* (Build|npbot|malicious)) {
# return 301 http://172.16.1.26;
# }
#*******************************************************
}
# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
#
#
#
# access_log /var/log/nginx/bubble.log combined if=$bubble;
--------------------------------
capture of the access.log is used to view the regex needed above :
139.184.203.136 - - [07/Sep/2022:11:33:21 +0100] "GET / HTTP/1.1" 200 4034 "http://17.253.35.203:6080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.136 - - [07/Sep/2022:11:33:21 +0100] "GET /css/css.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.136 - - [07/Sep/2022:11:33:21 +0100] "GET /css/all.min.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
tablet - ipad
139.184.203.136 - - [07/Sep/2022:11:46:46 +0100] "GET / HTTP/1.1" 200 4034 "http://17.253.35.201:6080/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.136 - - [07/Sep/2022:11:46:46 +0100] "GET /css/css.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.136 - - [07/Sep/2022:11:46:47 +0100] "GET /css/all.min.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
apple mac
139.184.203.203 - - [07/Sep/2022:11:47:20 +0100] "GET / HTTP/1.1" 200 4034 "http://17.253.35.205:6080/php/urlblock.php?args=AAAAdwAAABBB0x4lzbCN_25NIzE2mLydAAAAEIIpVFQWGkYTjew2YA~7insAAABHAAAAR8iLf9X97zxDBWSZrf5YmpPGUJ44TVhnKtWhwaO9DpSPda5XcaGK4Pa6a_3TED~US3plJBVXFDsA4JJW8AMQHBJBT~tEE0d5&url=http://captive.apple.com%2fhotspot-detect.html" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.203 - - [07/Sep/2022:11:47:20 +0100] "GET /css/css.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.203 - - [07/Sep/2022:11:47:20 +0100] "GET /css/all.min.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko)"
139.184.203.167 - - [07/Sep/2022:11:53:55 +0100] "GET / HTTP/1.1" 200 4034 "http://142.250.200.3:6080/" "Mozilla/5.0 (Linux; Android 12; Pixel 4 XL Build/SQ3A.220705.003.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36"
139.184.203.167 - - [07/Sep/2022:11:53:55 +0100] "GET /css/css.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Linux; Android 12; Pixel 4 XL Build/SQ3A.220705.003.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36"
139.184.203.167 - - [07/Sep/2022:11:53:55 +0100] "GET /css/all.min.css HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Linux; Android 12; Pixel 4 XL Build/SQ3A.220705.003.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36"
139.184.203.167 - - [07/Sep/2022:11:53:55 +0100] "GET /favicon.ico HTTP/1.1" 200 4034 "https://quarantine.sussex.ac.uk/" "Mozilla/5.0 (Linux; Android 12; Pixel 4 XL Build/SQ3A.220705.003.A1; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36"
#!/bin/bash
echo "Enter your string"
#above can be a command such as ls -l
read string
echo "Enter what you want substring counted"
read substring
#this can be just an a or 1 to obtain bigger numbers
count=$($string | sed 's/ /\n/g' | grep $substring | wc -l)
echo $count