Four ways to execute a shell script

shebang script explainedIf you need to execute a shell script and can’t get your head around the conflicting information out there, I’ll try to clear things up. There are quite a few ways to execute a shell script and each has its pros and cons. If you are coming from a Windows environment where the file extension dictates how we handle the file, then try not to think like this. A script can have no extension but still be run. So, let’s take a look at our four ways to execute a shell script.

 

Execute shell script by calling the filename (Method 1)

This method simply changes into the script’s containing directory and calls the script’s file name to execute it.

We can change into the directory first

$ cd /usr/bin

 

and then call the script thus:

$ ./myscript

 

Now, my preferred method is to consolidate these 2 lines into 1 , calling it from any directory by simply adding the full path to the file:

$ /usr/bin/myscript

 

If you have the shebang at the start of this script, then it will be executed by using the command interpreter that is specified directly after it.

Execute shell script by specifying an interpreter (Method 2)

You can also run a shell script by specifying the interpreter. You do this by adding the preferred interpreter within the command thus:

Execute the script using the bash interpreter

$ bash myscript

 

Execute the script using the sh interpreter

$ sh myscript

 

There are usually several interpreters available such as bash, sh,  csh, ksh and more.  Note that if you use a different interpreter in the shebang, this will be overridden by the one you specify.

Execute shell script with . ./ (Method 3)

If you execute the shell script by using . ./ (aka ‘dot space dot slash’), it will not fork a sub shell and you’ll see it executed in the current shell.

$ . ./myscript

 

Why do this? Well it’s normally used after we have changed something in the .bashrc or .bash_profile. Using this method of execution we won’t need to logout and login again.

$ cd ~

$ . ./.bashrc

$ . ./.bash_profile

Execute shell script with source command (Method 4)

source is a bash shell built-in command that executes the contents of the file, which is passed as argument, in the current shell. It has a synonym that you can use which is the dot or period (.)

This can replace the ‘dot space dot slash’ method.

source myscript [arguments]

. myscript [arguments]

 

A word of warning here though because ./ and source are not quite the same.

./myscript runs myscript as an executable file in a new shell
source myscript reads and executes commands in the current shell environment

To help further, ./myscript is not the same as . myscript, but . myscript is exactly the same as source myscript

 

Do you have a preferred method for executing shell scripts and if so, why? Let me know below.


Cannot find unread emails in Gmail inbox

I have had quite a few customers calling over the years to say that they cannot find unread emails in their Gmail inbox. It’s a common complaint and one which I have found can be quickly cured by doing the following.

Logon to Gmail in your browser (Chrome, Firefox, Internet Explorer, Safari etc).

Go to the search bar at the top of the Google page (the one with the blue and white ‘magnifying glass’ search button that looks like this):

cannot-find-unread-email-inbox-gmail

In that box, type this:

is:unread in:anywhere

Note that there is a space after the word ‘unread’ but not anywhere else. Copy and paste my text above if you aren’t sure.

Now press enter and you should see all of your unread emails! You can click to read individual ones or select them using their check boxes and then do ‘More’, then ‘Mark as read’.

Try some new search terms to get more out of Gmail

If you want to take things further, there are lots of useful search ‘operators’ that you can use within Gmail too. Get used to using these and you’ll open up a whole new level for this great email tool. Here’s a list of the most popular ones:

 

What you can search by Search operator & example
Specify the sender from:

Example: from:amy

Specify a recipient to:

Example: to:david

Words in the subject line Subject:

Example: subject:dinner

Messages that match multiple terms OR or { }

Example: from:amy OR from:david

Example: {from:amy from:david}

Remove messages from your results -

Example: dinner -movie

Find messages with words near each other. Use the number to say how many words apart the words can be AROUND

Example: dinner AROUND 5 friday

Messages that have a certain label label:

Example: label:friends

Messages that have an attachment has:attachment

Example: has:attachment

Messages that have a Google Drive, Docs, Sheets, or Slides attachment or link has:drive

has:document

has:spreadsheet

has:presentation

Example: has:drive has:document

Messages that have a YouTube video has:youtube

Example: has:youtube

Messages from a mailing list list:

Example: list:info@example.com

Attachments with a certain name or file type filename:

Example: filename:pdf

Example: filename: homework.txt

Search for an exact word or phrase " "

Example: "dinner and movie tonight"

Group multiple search terms together ( )

Example: subject:(dinner movie)

Messages in any folder, including Spam and Trash in:anywhere

Example: in:anywhere movie

Search for messages that are marked as important is:important

label: important

Example: is:important 

 

Starred, unread, or read messages is:starred

is:unread

is:read

Example: is:read is:starred

Messages that include an icon of a certain color has:yellow-star

has:blue-info

Example: has:purple-star

Recipients in the cc or bcc field cc:

bcc:

Example: cc:david

Note: You can’t find messages that you received on bcc.

Search for messages sent during a certain time period after:

before:

older:

newer:

Example: after:2004/04/16

Example: before:2004/04/18

Search for messages older or newer than a time period using d (day), m (month), and y (year) older_than:

newer_than:

Example: newer_than:2d

Chat messages is:chat

Example: is:chat movie

Messages delivered to a certain email address deliveredto:

Example: deliveredto:username@gmail.com

Messages in a certain category category:

Example: category:updates

Messages larger than a certain size in bytes size:

Example: size:1000000

Messages larger or smaller than a certain size in bytes larger:

smaller:

Example: larger:10M

Results that match a word exactly +

Example: +unicorn

Messages with a certain message-id header Rfc822msgid:

Example: rfc822msgid:200503292@example.com 

Messages that have or don’t have a label has:userlabels

has:nouserlabels

Example: has:nouserlabels 

Note: Labels are only added to a message, and not an entire conversation.

Credit for search operator list:  https://support.google.com/mail/answer/7190?hl=en


Lowest prices on Norton Antivirus renewals

cheap norton security discountBeing asked often about where to find the lowest priced Norton Antivirus renewal made me come up with this article. Symantec offer a renewal by credit card that is often too pricey for most people. With Norton Anti-virus being a capable product, it’s a shame to uninstall it so here are a few tips to get a new and fully licensed program at a much reduced price. And there’s nothing illegal about it!

You don’t have to uninstall your current product, simply buy another package (at much less than the price to renew your licence!) from our software shop which will open in a new window for you. When you open it up, use the serial number you find inside. Type this into your existing product and you’ll get another 12 months of updates (or more if you buy a 2 year package).

Remember to match the amount of user licences you have, eg if you have 3 PCs buy a 3-user licence.

Not got Norton Antivirus? Click here for the cheapest Norton Internet Security renewal or click here for the cheapest Norton 360 renewal

Don’t forget to ‘Tweet’ or Facebook ‘like’ this article if it saved you some cash! or tell your friends about our low-priced software shop


Install mod_GeoIP2 on Apache2 in CentOS 7

geoip-centos

If you need to install the excellent mod_geoip2 extension for Apache2 then it can be done fairly painlessly. First off, we need to make sure that we have gcc installed:

gcc --version

 

If you don’t have it then you could ‘yum install gcc’, but I prefer to install all development tools because they include gcc anyway:

yum groupinstall 'Development Tools'

 

Install the GeoIP development package

yum install geoip-devel

 

Install mod_geoip2 by fetching the latest version with wget. To check the latest version, take a look here first:

https://github.com/maxmind/geoip-api-mod_geoip2/releases

 

I’m installing 1.2.10 here with this, but replace the code in lines 1, 2 and 3 here with their latest version:

 wget https://github.com/maxmind/geoip-api-mod_geoip2/archive/1.2.10.tar.gz
 tar -zxvf 1.2.10.tar.gz
 cd geoip-api-mod_geoip2-1.2.10

 

Now we use the apxs (Apache Extension Tool) to build our extension modules for Apache:

apxs -i -a -L/usr/local/lib -I/usr/local/include -lGeoIP -c mod_geoip.c

 

If you haven’t got apxs then you’ll need to install httpd-devel.

Be aware that this overwrites httpd so backup your server in case this fails or you get strange results.

yum install httpd-devel

 

If this fails with “Error: Nothing to do”, then it’s fairly common. You’ll probably find that /etc/yum.conf is blocking the installation. We can get around this by either editing the configuration file or typing:

yum --disableexcludes=all install httpd-devel

 

You should now have mod_geoip2 installed on your server!


Who or what is [email protected]?

 

root notty whm ssh hackedIf you’re looking through WHM’s process manager and you see [email protected] mentioned as one of the processes, don’t be alarmed. It’s perfectly normal and it’s definitely not some hacker called ‘Notty’ who has suddenly got root permissions. Be honest, you’re here because you thought that 😉

You may also have seen sshd: [email protected] in the output of ps aux too.

Why notty?

The term ‘notty’ just represents ‘no tty’ which roughly translates as meaning ‘no terminal’. When you login locally to any Linux machine the terminal will always appear in the process list as ‘tty’. If a connection is made via SFTP or you are copying files with SCP (as I did here on a test server prior to bringing up the screenshot above) then it will show as no tty (notty).

Where does TTY come from?

Many years ago, user terminals that were connected to computers were clunky and noisy Electro-mechanical Teleprinters also known as Teletypewriters. They took the latter phrase and chopped some characters out to get the TTY abbreviation:

TeleTYpewriter = TTY

Since then, TTY has been used as the shortened name for a text-only console. Here’s a teletypewriter in action:

 

 

Now you can’t say that things haven’t progressed!

 

 


Cheapest Norton 360 renewal

cheap norton security discountI’m frequently asked by customers how to get the cheapest renewal price on Norton 360.  Symantec’s renewal price is really one of the highest for any Internet Security product.  It is a capable package though and worth keeping on your PC. The best way by far is to purchase a new fully licensed program at a reduced price and install that. Nothing underhand, just a new product at a price much lower than Norton currently quote for renewal.

The beauty of this is that you don’t have to uninstall your current product if it is the same ‘family’ as the one you are installing, simply match the product family. For example, if you have Norton Security, get a Norton Security package with any version number as they all qualify for Norton’s free upgrade to the latest version anyway! If you have the older Norton 360 then get Norton Security and uninstall Norton 360 first.

Do Norton really offer a free upgrade?

Yes, most versions of Norton qualify for a free upgrade to the latest version in that product family. If you download the latest installation program, Norton will auto-detect and remove your older version and then install the newer one too, making it even simpler to install.

Please note

You can change to another security software at this point. From doing lots of virus clean-up work and labs testing, I would recommend uninstalling the Norton product and installing my preferred security suite and consistent labs test winner Kaspersky Total Security. Norton is quite capable but Kaspersky definitely has the edge on speed and low resource usage.

A word of warning. Norton products such as Norton 360, Norton Internet Security and Norton Antivirus are now retired in favour of “Norton Security” and “Norton Security with Backup”. Confused? This article explains more: New Norton product family (opens in a new window).

So to recap, if your Norton 360 has expired, then take a look in my software shop (opens in a new tab) and buy either a Norton or Kaspersky product at prices cheaper than Symantec’s renewal rates. If you want to upgrade to another software product (such as Kaspersky) then simply uninstall the existing Norton software, restart the computer and then install the Kaspersky product.

Don’t forget to ‘Tweet’ or Facebook ‘like’ this article if it saved you some cash!

Shop for Norton products now


Outlook emails stay in Outbox after Windows 10 upgrade

email-settings-pop-imap-btconnect-outlookAre you getting your Outlook emails stuck in your Outbox after upgrading to Windows 10? I’ve seen this happen on several machines and it really seems to be a problem where Windows corrupts the Outlook database and/or profile on many versions of Microsoft Office (2007, 2010 and 2013). The easiest fix and one that I’d recommend here is to delete or move the stuck emails then close all programs that are open such as Outlook.

Now we can use the in-built Windows “System File Checker” that will scan your PC and repair any corrupt files that it finds. To do this:

  • Click Start
  • Type cmd in the Search box
  • Right-click Command Prompt and then click ‘Run as administrator’. If you are prompted for an administrator password or for a confirmation then type the password or click ‘Allow’
  • In this black window (the command prompt) that appears, type in sfc /scannow noting the space before the forward slash
  • Press enter and go and grab a delicious cup of coffee because this will take a while

Note: Do not close this Command Prompt window until the verification is 100% complete. The scan results will be shown after this process is finished.

Technical information for nerds
The sfc /scannow command will scan all protected system files, and replace corrupted files with a cached copy that is located in a compressed folder at %WinDir%\System32\dllcache.
The %WinDir% placeholder represents the Windows operating system folder. For example, C:\Windows.

The time taken to complete this scan is different on every PC but usually can range from 20 minutes to an hour or more. If it solves your problem (which it has on over 50 client PCs to date) then please take a minute to drop a comment below or maybe buy something through our shop to say thanks.

 


Reset Windows Server 2012 Administrator password

server 2012 password resetTo reset the Administrator password on your Windows server 2012 installation, you’ll need to do the following:

Boot from the Microsoft Windows Server 2012 DVD

  1. From the Windows setup menu, click “Next”
  2. Select “Repair your computer”
  3. Click on “Troubleshoot”
  4. Under Advanced options, click “Command Prompt”
  5. Type “diskpart” and hit Enter
  6. Type “list volume” and hit Enter. This will show you your (current) drive letter allocated to the drive where Windows is installed. Note  – if you don’t see any volumes listed and this is the first boot cycle for a new Server 2012 installation, then I have seen this on a few HP servers and you’ll need to go and run the setup again from within the Intelligent Provisioning area.
  7. Make a note of the drive letter and type “exit” then press enter to leave diskpart (but stay in the command prompt window)
  8. Presuming the letter is d, then type “d:” and press enter to change to this drive
  9. Now type  “cd Windows\system32” and press enter which will take you into the system32 folder
  10. Type “ren Utilman.exe Utilman.bak” and press enter
  11. Type “copy cmd.exe Utilman.exe” and press enter
  12. Close the command prompt and then click “Continue”
  13. The server should now reboot to the logon screen. Press the Windows key + u to open a command prompt
  14. At the prompt you can change the password by typing “net user administrator xyz” where xyz is your new super-secure password!
  15. Now, for security we must do one last thing. Once we are back in Windows, open Explorer, navigate to Windows\system32 and rename Utilman.bak to Utilman.exe

 

Hopefully this gets you out of a sticky situation, leave me a comment if it has helped.

 


Country codes for mod_security, CSF and htaccess

Her’s a list of useful country codes that we can use in many rule-based filtering situations on servers.

AD Andorra
AE United Arab Emirates
AF Afghanistan
AG Antigua and Barbuda
AI Anguilla
AL Albania
AM Armenia
AN Netherlands Antilles
AO Angola
AQ Antarctica
AR Argentina
AS American Samoa
AT Austria
AU Australia
AW Aruba
AZ Azerbaijan
BA Bosnia and Herzegovina
BB Barbados
BD Bangladesh
BE Belgium
BF Burkina Faso
BG Bulgaria
BH Bahrain
BI Burundi
BJ Benin
BM Bermuda
BN Brunei Darussalam
BO Bolivia
BR Brazil
BS Bahamas
BT Bhutan
BV Bouvet Island
BW Botswana
BY Belarus
BZ Belize
CA Canada
CC Cocos (Keeling) Islands
CF Central African Republic
CG Congo
CH Switzerland
CI Cote D’Ivoire (Ivory Coast)
CK Cook Islands
CL Chile
CM Cameroon
CN China
CO Colombia
CR Costa Rica
CS Czechoslovakia (former Republic)
CU Cuba
CV Cape Verde
CX Christmas Island
CY Cyprus
CZ Czech Republic
DE Germany
DJ Djibouti
DK Denmark
DM Dominica
DO Dominican Republic
DZ Algeria
EC Ecuador
EE Estonia
EG Egypt
EH Western Sahara
ER Eritrea
ES Spain
ET Ethiopia
FI Finland
FJ Fiji
FK Falkland Islands (Malvinas)
FM Micronesia
FO Faroe Islands
FR France
FX France, Metropolitan
GA Gabon
GB Great Britain (UK)
GD Grenada
GE Georgia
GF French Guiana
GH Ghana
GI Gibraltar
GL Greenland
GM Gambia
GN Guinea
GP Guadeloupe
GQ Equatorial Guinea
GR Greece
GS S. Georgia and S. Sandwich Isls.
GT Guatemala
GU Guam
GW Guinea-Bissau
GY Guyana
HK Hong Kong
HM Heard and McDonald Islands
HN Honduras
HR Croatia (Hrvatska)
HT Haiti
HU Hungary
ID Indonesia
IE Ireland
IL Israel
IN India
IO British Indian Ocean Territory
IQ Iraq
IR Iran
IS Iceland
IT Italy
JM Jamaica
JO Jordan
JP Japan
KE Kenya
KG Kyrgyzstan
KH Cambodia
KI Kiribati
KM Comoros
KN Saint Kitts and Nevis
KP Korea (North)
KR Korea (South)
KW Kuwait
KY Cayman Islands
KZ Kazakhstan
LA Laos
LB Lebanon
LC Saint Lucia
LI Liechtenstein
LK Sri Lanka
LR Liberia
LS Lesotho
LT Lithuania
LU Luxembourg
LV Latvia
LY Libya
MA Morocco
MC Monaco
MD Moldova
MG Madagascar
MH Marshall Islands
MK Macedonia
ML Mali
MM Myanmar
MN Mongolia
MO Macau
MP Northern Mariana Islands
MQ Martinique
MR Mauritania
MS Montserrat
MT Malta
MU Mauritius
MV Maldives
MW Malawi
MX Mexico
MY Malaysia
MZ Mozambique
NA Namibia
NC New Caledonia
NE Niger
NF Norfolk Island
NG Nigeria
NI Nicaragua
NL Netherlands
NO Norway
NP Nepal
NR Nauru
NT Neutral Zone
NU Niue
NZ New Zealand (Aotearoa)
OM Oman
PA Panama
PE Peru
PF French Polynesia
PG Papua New Guinea
PH Philippines
PK Pakistan
PL Poland
PM St. Pierre and Miquelon
PN Pitcairn
PR Puerto Rico
PT Portugal
PW Palau
PY Paraguay
QA Qatar
RE Reunion
RO Romania
RU Russian Federation
RW Rwanda
SA Saudi Arabia
Sb Solomon Islands
SC Seychelles
SD Sudan
SE Sweden
SG Singapore
SH St. Helena
SI Slovenia
SJ Svalbard and Jan Mayen Islands
SK Slovak Republic
SL Sierra Leone
SM San Marino
SN Senegal
SO Somalia
SR Suriname
ST Sao Tome and Principe
SU USSR (former)
SV El Salvador
SY Syria
SZ Swaziland
TC Turks and Caicos Islands
TD Chad
TF French Southern Territories
TG Togo
TH Thailand
TJ Tajikistan
TK Tokelau
TM Turkmenistan
TN Tunisia
TO Tonga
TP East Timor
TR Turkey
TT Trinidad and Tobago
TV Tuvalu
TW Taiwan
TZ Tanzania
UA Ukraine
UG Uganda
UK United Kingdom
UM US Minor Outlying Islands
US United States
UY Uruguay
UZ Uzbekistan
VA Vatican City State (Holy See)
VC Saint Vincent and the Grenadines
VE Venezuela
VG Virgin Islands (British)
VI Virgin Islands (U.S.)
VN Viet Nam
VU Vanuatu
WF Wallis and Futuna Islands
WS Samoa
YE Yemen
YT Mayotte
YU Yugoslavia
ZA South Africa
ZM Zambia
ZR Zaire
ZW Zimbabwe

A few lesser-used ones below, but for completeness here they are:

ARPA Arpanet
COM US Commercial
EDU US Educational
GOV US Government
INT International
MIL US Military
NATO Nato field
NET Network
ORG Non-Profit Organization


Crash Plan backup software full review

CrashPlan has been around for a while now and is looking like one of the best solutions out there for business and personal backups.

With no storage size limits, bandwidth caps or file-type restrictions, Crash Plan really has lots going for it. On top of this, there’s enterprise-class hardware and military-grade security with no extra fees payable.

What I particularly like about Crash Plan is that there is free backup to an external drive and any trusted, internet-connected computer. You can also subscribe to their robust cloud-based destination, “CrashPlan Central” and this is certainly worth the extra money. It’s as quick as any cloud-based backup we have tested and the interface is functional and quite slick.

See what Crash Plan can offer here


crashplan online backup