Thu, Mar 31, 2016 11:12 pm
Bash on Windows
Microsoft announced yesterday that the
Windows 10 Anniversary Update, which is expected to be shipped this summer,
will include support for the
Bash shell commonly provided on
Unix and
Linux systems
as well as with Apple
OS X systems.
Microsoft had previously provided software called
Windows
Services for Unix (SFU), which provided a Unix subsystem for Microsoft
Windows systems, but discontinued that software.
Last year the Microsoft PowerShell Team announced that Microsoft was
going to provide SSH server software, a staple for remote management of
Unix and Linux systems and server software available by default with OS X.
I would certainly be appreciative of having the same command line tools,
such as AWK,
grep, etc. available under a
Bash shell on Linux systems on Microsoft Windows systems, also. And, since I
usually install a third-party SSH server application, such as
Bitvise SSH Server,
Copssh,
freeSSHd,
PowerShell SSH Server for Windows, or
SilverSHield, to be
able to remotely connect to Microsoft Windows for command line troubleshooting, I'm hoping that will be available by some this year or next as well, though
I'm not aware of the date it is expected to become available.
References:
-
Ubuntu’s bash and Linux command line coming to Windows 10
By: Peter Bright
Date: March 30, 2016
Ars Technica
-
Windows 10: /bin/bash-supporting “Anniversary Update” coming this summer
By: Peter Bright
Date: March 30, 2016
Ars Technica
-
Microsoft bringing SSH to Windows and PowerShell
By: Peter Bright
Date: June 2, 2015
Ars Technica
-
Windows Services for UNIX Version 3.0
Microsoft TechNet
-
Looking Forward: Microsoft Support for Secure Shell (SSH)
By: PowerShell Team
Date: June 3, 2015
Windows PowerShell Blog
[/os/windows]
permanent link
Wed, Mar 30, 2016 10:36 pm
802.1X Authentication on an OS X System
When I attempted to connect to a wireless network, after changing a password
for authenticating with systems in use at a location, when I arrived at that
location today with my MacBook Pro laptop, I found that instead of
connecting to the wireless network at that location automatically,
I was not able to establish a connection to the WiFi network. When
I checked the
Network settings under
System Preferences, I found
that for the Wi-Fi connection it was showing "Self-Assigned IP" with the
message "Wi-Fi has the self-assigned IP address 169.254.57.115 and will not
be able to connect to the Internet. For that network, the laptop needs to
authenticate with
802.1X
to gain access to the network." But the status for 802.1X was stuck at
"Authenticating." I was able to successfully authenticate after changing
the "802.1X Password" for the wireless network through the
Keychain
Access utility.
[ More Info ]
[/os/os-x/802_1x]
permanent link
Mon, Mar 28, 2016 10:34 pm
Summing the file sizes in a directory
If you wish to calculate a total size for all files in a directory on
a Unix, Linux, or Mac system running Apple's OS X operating system,
two ways to do so are by using the awk utility or with the Python
programming language. E.g.,
ls -l example | awk '{sum +=$5} END
{print sum}'
. For a Python solution, you can use the
dirsize.py
program.
[ More Info ]
[/os/unix/commands]
permanent link
Sun, Mar 27, 2016 9:02 pm
Setting the padding and border for a table with CSS
With
HTML 4, you can stipulate that a border be placed around
the cells in a
table using the
border
parameter, e.g.:
<table border="1">
. However with
HTML5, use of the "border=" attribute for putting a border around
elements of a table has been deprecated as has setting the padding around
elements in a table with
cellpadding
, e.g.,
<table border="1" cellpadding="3">
. If you check your HTML
code for adherence to the HTML 5 standard with the
Nu Html Checker provided by the
World
Wide Web Consortium, you will see an warning displayed if you have used
the border attribute and an error displayed for use of the cellpadding
attribute. You can achieve an equivalent table display using
Cascading Style Sheets, however, by
adding a style section for
the table and the th and td elements to set the border and
setting cell padding
in a style section or for each td and th element
[/network/web/html/css]
permanent link
Fri, Mar 25, 2016 9:45 pm
Creating a registry entry to run a program at login
If you wish to have a program run whenever a
user logs into the system, then you can add an entry to
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
in the
Windows Registry, assuming you are logged into
the system as the user for which you wish to have the program run at logon at
the time you add the entry to the registry, so that
HKEY_CURRENT_USER (HKCU), which applies to the currently logged in user,
applies to that user's account.
One way you can add a new entry in the registry for a program to run when
the user logs in is to use the regedit
program
that comes with the Windows operating system and which is normally found in the
C:\Windows
directory.
[ More Info ]
[/os/windows/registry]
permanent link
Thu, Mar 24, 2016 11:29 pm
Displaying a Wi-Fi password under OS X
If you need to know a saved wireless network password on a system running
Apple's
OS X
operating system, e.g. a MacBook Pro, you can do find that
information using the
Keychain Access program found in
Applications/Utilities
. To find the information using that
utility, open it, then click on
Edit then
Find and
search for the
SSID for the wireless router or click on
Passwords under
Category in the left pane of the window and look for it in the
list you will see. You can then double-click on a relevant entry to see
the password/key. Alternatively, you can use the command line
security program with the
find-generic-password
option
to display the password.
[ More Info ]
[/os/os-x]
permanent link
Wed, Mar 23, 2016 10:34 pm
Excluding multiple patterns with grep
If you wish to exclude lines containing a specified pattern when using the
grep command
on a
Unix,
Linux, or
OS X system,
you can do so using the
-v
or
--invert-match
. option.
-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v
is specified by POSIX.)
E.g., suppose I have a file names.txt
containing the following
names:
$ cat names.txt
John Smith
Paul McCartney
Bob Jones
Allen Smith
Greg Smith
Bob Smith
Carl Smith
John Doe
If I want to view all lines except for those containing "Allen", I can
use grep -v "Allen" names.txt
. But what if I want to exclude
more than one pattern, e.g. any line containing "Allen" or "Bob". I could
pipe the output of one grep command to another grep command with
grep -v "Allen" names.txt | grep -v "Bob"
. Or you can perform
a logical disjunction using the
"pipe"
character, i.e., "|
", aka a "vertical bar".
$ grep -v "Allen\|Bob" names.txt
John Smith
Paul McCartney
Greg Smith
Carl Smith
John Doe
$
In the above example, I am instructing
grep to ignore any lines
containing either Allen or Bob in the line. Because the pipe character has
another meaning to the Bash shell, i.e., it is used by the shell to "pipe" the
output of one command to another with the output of the first command becoming
the input of the second, its meaning must be "escaped" to be processed by
grep as a logical disjunction symbol. That is done by preceding the character
with a
backslash, which is an
escape character.
[/os/unix/commands]
permanent link
Tue, Mar 22, 2016 11:27 pm
Blosxom - Magic number checking on storable file failed
When I attempted to access blog postings on this site where I use
Blosxom for the blog,
I saw the message below:
Internal Server Error
The server encountered an internal error or
misconfiguration and was unable to complete
your request.
Please contact the server administrator at
webmaster@moonpoint.com to inform them of the time this error occurred,
and the actions you performed just before this error.
More information about this error may be available
in the server error log.
I was able to access webpages that were not blog postings. When I checked
the site's error log file, I saw many entries similar to the following
indicating that others were experiencing the same problem when accessing
the site:
[Tue Mar 22 11:43:12.276013 2016] [cgi:error] [pid 24979] [client 136.243.36.80:
52035] AH01215: Magic number checking on storable file failed at /usr/lib64/perl
5/vendor_perl/Storable.pm line 381, <DATA> line 32, at /home/jdoe/public_html/su
pport/blog/plugins/calendar line 322.
I use a Blosxom
calendar plugin, so I checked line 322 in the calendar plugin file and
found the following code:
if (!Storable->can('lock_retrieve')) {
debug(1, "cache disabled, Storable::lock_retrieve not available");
$use_caching = 0;
return 0;
}
$cache = (-r $cachefile ? Storable::lock_retrieve($cachefile) : undef);
The line starting with "$cache" is line 322. I checked the cache file
for the plugin which is under the plugins/state
directory
for the blog software and saw it was zero bytes in length.
# ls -al /home/jdoe/public_html/support/blog/plugins/state/.calendar.cache
-rw-r--r--. 1 apache apache 0 Mar 22 11:42 /home/jdoe/public_html/support/blog/plugins/state/.calendar.cache
So I deleted the file; it will be recreated automatically when the blog
is accessed after it is deleted.
# rm /home/jdoe/public_html/support/blog/plugins/state/.calendar.cache
rm: remove regular empty file ‘/home/jdoe/public_html/support/blog/plugins/state/.calendar.cache’? y
Deletion of the .calendar.cache
file fixed the problem. When
I refreshed the page in my browser for a blog posting from years ago I
had been attempting to view I could then see it and access other blog
postings as well. I also saw the file had been recreated.
# ls -al /home/jdoe/public_html/support/blog/plugins/state/.calendar.cache
-rw-r--r--. 1 apache apache 94578 Mar 22 21:54 /home/jdoe/public_html/support/blog/plugins/state/.calendar.cache
[/network/web/blogging/blosxom]
permanent link
Sun, Mar 20, 2016 11:08 pm
Saving a song from an Internet source with VLC on a MAC
After
installing the VLC media player on a Mac
OS X system, if you wish to save a song that you have been listening to
from one of the Internet sources it lists, such as Jamendo Selections, you
can do so through its
Streaming/Exporting Wizard. The wizard will
give you the option to save the song in a number of file formats, e.g.
Ogg, for a song, to the hard drive of the Mac or an external device attached
to it.
[More Info ]
[/os/os-x/software/vlc]
permanent link
Sat, Mar 19, 2016 10:51 pm
Determining which program is listening on a port under Windows
If you want to know which application is listening on a particular
network port on a Microsoft Windows system, e.g., port 80, the port used
for HTTP connections to a web server, you can obtain that information
from a command line interface (CLI) by
obtaining a command prompt and
using the netstat and tasklist commands which are provided with the
operating system; you do not need to install any additional software,
though there are programs that will allow you to view that information
from a graphical user interface (GUI).
[ More Info ]
[/os/windows/network]
permanent link
Fri, Mar 18, 2016 3:38 pm
Using a SOCKS proxy server from an OS X system
If you wish to connect to a
Socket Secure
(SOCKS) proxy server from a system running Apple's OS X operating
system, you can do so through the
Network option from
System
Preferences by clicking on the
Advanced button, then
selecting the
Proxies tab and then checking the check box next
to
SOCKS Proxy and providing the relevant values or you can use
the
networksetup command
to configure SOCKS proxy server support from a command line interface
(CLI), e.g. a
Terminal window.
[ More Info ]
[/os/os-x]
permanent link
Thu, Mar 17, 2016 9:53 pm
Determine the currently connected Wi-Fi network from the command line on OS X
If you need to determine the currently connected WiFi network from a
command line interface (CLI), aka a shell prompt, on an Apple OS X
system, e.g., a MacBook Pro laptop, you can do so by opening a Terminal
window (the application is in
/Applications/Utilities
) and
issuing the command
networksetup -getairportnetwork wifi_device
where
wifi_device is the port used for wireless connections
on the system. You can determine the hardware port used for Wi-Fi
connectivity on the system by issuing the command
networksetup -listallhardwareports
and then piping its
output into the
grep command looking for
Wi-Fi
in the output and when it is found displaying that line and
the two lines after it. E.g., in the example below,
en0
is the
relevant device interface for wireless connections and the
SSID for the currently connected Wi-Fi network is "Hogwarts".
$ networksetup -listallhardwareports | grep -A 1 "Wi-Fi"
Hardware Port: Wi-Fi
Device: en0
$ networksetup -getairportnetwork en0
Current Wi-Fi Network: Hogwarts
[/os/os-x]
permanent link
Wed, Mar 16, 2016 10:40 pm
Extracting numbers from a text string with grep
The
grep
command-line utility found on
Unix,
Linux, and
OS X
systems can be used to extract
strings from files or other data input to the command.
As an example of extracting digits from a string, suppose I have the
following text that contains a version number between
<string>
and
</string>
:
<string>14.6.0</string>
I only want to see the 14.6.0
, so I can use the grep
command with the -o
option to specify I ony want the text
that matches a specified pattern displayed. The pattern I can use is
'[0-9.]\+
'.
[ More Info ]
[/os/os-x]
permanent link
Mon, Mar 14, 2016 10:39 pm
Correcting an issue with the touchpad not working under Ubuntu 12.04
When I booted an eMachines 250-1162 netbook running
Ubuntu 12.04 today, I was able to tab between fields on a webpage, but the
touchpad
was not working - I could not move the mouse pointer. I hit the
Ctrl-Alt-F2
keys simultaneously to obtain a
console
window where I entered the following command:
$ gksudo modprobe -r psmouse
(gksudo:2607): Gtk-WARNING **: cannot open display:
I then switched back to the
graphical
user interface (GUI) console by hitting Ctrl-Alt-F7. I was then
able to move the mouse pointer using the touchpad.
References:
-
Resetting the mouse in Ubuntu
Date: August 1, 2015
MoonPoint Support
[/os/unix/linux/ubuntu]
permanent link
Sun, Mar 13, 2016 10:26 pm
hostname options not working
On a CentOS 7 Linux system, I could issue the command
hostname
and see the name for the system displayed.
Yet, if I tried entering any option for the command, I received the
error message "Name or service not known".
# hostname -a
hostname: Name or service not known
# hostname -i
hostname: Name or service not known
# hostname -f
hostname: Name or service not known
# hostname --fqdn
hostname: Name or service not known
[ More
Info ]
[/os/unix/linux/centos]
permanent link
Sat, Mar 12, 2016 5:24 pm
Determining the username under which PHP is running
I wanted to determine the user name under which PHP was running for a
WordPress blog on a hosting site. To do so, I placed a PHP script,
whoami_here.php
, in the home folder for the WordPress installation
and then accessed the webpage for that script via a browser, e.g.
http://example.com/whoami_here.php
.
There are a variety of methods you can use to check on which account
PHP is running under, e.g., <?php passthru("whoami"); ?>
,
though some methods may not work on some systems.
[ More Info ]
[/languages/php]
permanent link
Fri, Mar 11, 2016 10:37 pm
Microsoft Excel quit unexpectedly
Microsoft® Excel® for Mac 2011 (Version 14.6.0) crashed and
when it reopened it crashed again. When it reopened, I saw
the message "Microsoft Excel quit unexpectedly. Click Reopen to
open the application again. Click Report to see more detailed
information and send a report to Apple."
I was able to stop it from continually crashing by choosing not to reopen
all of the spreadsheets that had previously been opened. When it displayed
the message "This workbook contains macros. Do you want to disable macros before
opening the file?", I chose "Do Not Open" for some of the workbooks that
previously had been open.
I was then able to successfully open the application and continue working
on other workbooks that had been open in Excel.
I checked for the crash logs related to the problem in
~/Library/Logs/DiagnosticReport
.
I saw two crash reports for today, March 11, 2016.
$ ls ~/Library/Logs/DiagnosticReports/
Google Chrome_2016-02-24-131912_GSSLA15122293.crash
Microsoft Excel_2016-03-11-114210_GSSLA15122293.crash
Microsoft Excel_2016-03-11-141557_GSSLA15122293.crash
PGP Engine_2016-02-22-212124_GSSLA15122293.crash
When I checked both Excel crash reports, I found that the cause was logged as
a stack overflow. I looked for the line that immediately follows the
"Application Specific Information:" line in the files, which is why I used
the -A 1
argument to the
grep
command.
GSSLA15122293:/ johndoe1$ grep -A 1 "Application Specific Information:" ~/Library/Logs/DiagnosticReports/Microsoft\ Excel_*.crash | grep -v "Application"
/Users/johndoe1/Library/Logs/DiagnosticReports/Microsoft Excel_2016-03-11-114210_GSSLA15122293.crash-[20077] stack overflow
--
/Users/johndoe1/Library/Logs/DiagnosticReports/Microsoft Excel_2016-03-11-141557_GSSLA15122293.crash-[23349] stack overflow
[/software/office]
permanent link
Thu, Mar 10, 2016 10:55 pm
Adobe Flash vulnerability security updates released on March 10, 2016
Adobe has released an emergency update for its
Flash
media player which contains fixes for about two dozen
critical
vulnerabilities. Adobe defines a critical vulnerability as "A
vulnerability, which, if exploited would allow malicious native-code
to execute, potentially without a user being aware.
Adobe Security Bulletin ASP16-08 lists the following
Common Vulnerabilities and Exposures (CVEs) addressed in the new release:
CVE-2016-0960
CVE-2016-0961
CVE-2016-0962
CVE-2016-0963
CVE-2016-0986
CVE-2016-0987
CVE-2016-0988
CVE-2016-0989
CVE-2016-0990
CVE-2016-0991
CVE-2016-0992
CVE-2016-0993
CVE-2016-0994
CVE-2016-0995
CVE-2016-0996
CVE-2016-0997
CVE-2016-0998
CVE-2016-0999
CVE-2016-1000
CVE-2016-1001
CVE-2016-1002
CVE-2016-1005
CVE-2016-1010
[ More Info ]
[/network/web/browser]
permanent link
Wed, Mar 09, 2016 10:37 pm
Viewing or setting a time server under OS X
If you need to determine what
Network Time Protocol (NTP) server is being used on an Apple OS X
system from a command line interface (CLI), aka a shell prompt, you
can use the
systemsetup
command with the
-getnetworktimeserver
option.
$ sudo systemsetup -getnetworktimeserver
Password:
Network Time Server: time.example.com
If you wish to set the time server you can use the
-setnetworktimeserver
command, e.g.:
$ sudo systemsetup -setnetworktimeserver us.pool.ntp.org
[/os/os-x]
permanent link
Mon, Mar 07, 2016 10:48 pm
Determining the modules which are loaded in Apache
The
Apache HTTP server software supports many features
via
compiled
modules which extend the core functionality of the web server software.
Modules support various authentication methods,
URL
rewriting,
proxying, etc. You can check on what modules are loaded
using the command
httpd -t -D DUMP_MODULES
or with PHP using
apache_get_modules()
.
[ More Info ]
[/network/web/server/apache]
permanent link
Sun, Mar 06, 2016 9:55 pm
Viewing and setting the host name on a Linux or OS X system
To view the host name for a
Linux or
OS X system you
are logged into, you can use the
uname command
with the
-n
option. On a Linux system, you can also use
--nodename
in lieu of
-n
, but
--nodename
won't work on OS X. If the host name has not been set,
you will see
localhost.localdomain
displayed.
$ uname --nodename
localhost.localdomain
You can also use the
hostname command on a Linux or OS X system to show or set the host name. To
show the host name, issue the command without any parameters
$ hostname
localhost.localdomain
On some versions of Linux, e.g.,
CentOS and
Ubuntu, you can also view the host name using the
sysctl
command; it won't work on OS X, however.
[ More Info ]
[/os/unix]
permanent link
Sat, Mar 05, 2016 10:15 pm
PowerShell get-process cmdlet
On a Microsoft Windows system, you can obtain a list of all processes that
are currently running from a command line interface (CLI) using the
Windows PowerShell cmdlet
get-process
. To see all running
processes, obtain a PowerShell prompt and type
get-process
.
PS C:\> get-process
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
100 9 1472 848 71 14.06 41452 adb
1018385 17 3028 1008 99 5,303.64 101076 AdobeARM
79 7 1200 1336 44 56112 armsvc
127 10 7956 9444 37 101.42 120812 audiodg
9244 279 233224 22368 1019 1916 avp
1334 72 51656 3436 263 1,856.22 11692 avp
427 34 18864 11000 1510 1984 certsrv
321 29 52752 71604 501 3.73 6524 chrome
249 25 44344 9356 290 801.09 7820 chrome
<text snipped>
268 20 4876 11112 60 121708 w3wp
227 21 618252 31084 688 5428 wbengine
84 8 892 324 41 656 wininit
181 10 2432 2752 58 684 winlogon
364 44 13596 17920 153 2,894.47 102896 WinSCP
1672 20 9228 18008 81 52428 WmiPrvSE
4884 20 16476 8936 61 3252 WSSBackup
PS C:\>
The column values are as follows:
-
Handles: The number of process handles that the process opened. A
handle is an integer that Windows assigns to processes. For instance, each
process thread is typically assigned a handle.
-
NPM(K): Non-paged memory the process is using, in kilobytes.
-
PM(K): Pageable memory the process is using, in kilobytes.
-
WS(K): Process working set, in kilobytes. The value refers to the number of
memory pages that the process recently accessed.
-
VM(M): Virtual memory the process is using.
-
CPU(s): Processor time used on all processors, in seconds.
-
Id: Process Identifier (PID).
-
ProcessName: The name of the process.
[ More Info ]
[/os/windows/PowerShell]
permanent link
Fri, Mar 04, 2016 9:37 pm
Workday function
Sometimes you may need to determine the number of work days from one date
to another in a
Microsoft Excel,
Google Sheets, or
Apache
OpenOffice Calc spreadsheet. E.g., you may need to exclude Saturdays,
Sundays, and holidays from a calculation. All three spreadsheet programs provide
a
WORKDAY
function that you can use to calculate dates based on
business work days rather than just the total number of days from a start
date. For Microsoft Excel on both Microsoft Windows and OS X and Google Sheets,
the syntax for the
WORKDAY
function is as follows:
WORKDAY(start_date, num_days, [holidays])
For OpenOffice Calc, you need to separate the parameters with a semicolon
rather than a colon. I.e.:
WORKDAY(Start_date; num_days; [holidays])
If you separate the parameters with a comma in Calc, it will display
Err:508
.
"Holidays" is enclosed in brackets to indicate it is an optional parameter, you
would not actually include the brackets if you specified holidays.
The arguments to the function have the following meaning:
-
Start_date - Required. A date that represents the starting date for
a calculation
-
num_days - Required. The number of nonweekend and nonholiday days before
or after the start_date. A positive value yields a future date while a negative
value yields a past date.
-
holidays - Optional. An optional list of one or more dates to exclude
from the working calendar, such as state and federal holidays and floating
holidays. The list can be either a range of cells that contain the dates
or an array constant of the serial numbers that represent the dates.
E.g., I need to determine the date when work requests that should
be completed within 5 business days after approval should be completed.
I can display the required implementation date for each request in a
worksheet by using the formula =WORKDAY(cell,5)
where
cell holds the approval date. E.g., if the approval date is in cell
A2, I can set the formula for the required implemenation date to be
WORKDAY(A2,5)
for Excel or Google Sheets or
WORKDAY(A2;5)
for Apache OpenOffice Calc.
If there was no date in cell A2, Excel will display January 6, 1900
in the cell holding the implemenation date, e.g. 1/6/00
, if
the date format is D/M/YY (day/month/2-digit year), but OpenOffice Calc
and Google Sheets will display January 5, 1900. Microsoft Excel stores
dates as sequential serial numbers so they can be used in calculations
and, by default, uses January 1, 1900 as serial number 1. If you have a
date field containing January 1, 2008 that is equivalent to 39,448, which
you would see if you put that day in a cell formatted to hold a date then
changed the format to be a number. January 1, 2016 is 42,370. January 1,
2008 is 39,448 days after January 1, 1900 and January 1, 2016 is 42,370
days after that date.
Why do Google Sheets and Apache OpenOffice Calc show January 5,
1900 as the calculated date when there is no date in the start_date
field while Microsot Excel displays January 6, 1900? Long before Microsoft
became a dominant player in the spreadsheet market,
Lotus 1-2-3
from
Lotus Development Corporation was a dominant spreadsheet in the personal
computer market. There was a bug in Lotus 1-2-3 due to the developers
assuming that the year 1900 was a leap year; it was not. When Microsoft released
Excel they had to compete with Lotus 1-2-3, the then dominant spreadsheet for
personal computers, so Microsoft needed to ensure that spreadsheets created in
Lotus 1-2-3 returned the same results in Excel, so for compatibility retained
the incorrect assumption regarding the year 1900 - see the Microsoft article
Excel incorrectly
assumes that the year 1900 is a leap year and
Excel Date Conversion (Days from 1900) regarding making an allowance for
that incorrect assumption. Google Sheets and Apache OpenOffice Calc did not
retain that incorrect assumption regarding the year 1900 and so you will
see January 5 used in certain calculations in those spreadsheets where
January 6, 1900 is used by Exel, which is why sometims you may get
differing results for date calculations between those spreadsheet
programs.
If an argument to the workday
function is not a valid
date, e.g., 2/30/16 for February 30, 2016, which is not a valid date,
you will see #VALUE!
displayed by the function in all three
spreadsheets. In all three spreadsheets, if days is not an integer, the
number is truncated to an integer value. E.g., if you used the formula
=WORKDAY(A2,5.7)
you would get the same result as entering
WORKDAY(A2,5)
.
[/os/windows/office/excel]
permanent link
Thu, Mar 03, 2016 10:02 pm
Downloading a web page with Python using command line parameters
If you wish to download a web page with a
Python
script, you can imput the
urllib2
module into a Python
script as explained at
Downloading a web page with Python. I've modified the script posted there
to allow the webpage
URL
and output file name to be specified as command line arguments to the
script:
#!/usr/bin/python
# download_page
# download a webpage to a specified file. The script takes two parameters:
# the URL of the page to download and a file name to be used to hold
# the downloaded web page.
import urllib2, sys
try:
sys.argv[1]
except IndexError:
print "Error - URL missing! Usage: ./download_page.py download_page_url outfile"
sys.exit(1)
else:
url = sys.argv[1]
try:
sys.argv[2]
except IndexError:
print "Error - missing output file name! Usage: ./download_page.py download_page_url outfile"
sys.exit(1)
else:
outfile = sys.argv[2]
page = urllib2.urlopen(url)
source = page.read()
downloadFile = open(outfile, 'w')
downloadFile.write(source)
downloadFile.close()
The sys
module is imported to check the command line
arguments using sys.argv[x]
, where x. is the
number specifying the argument; sys.argv[0]
is always the
name of the script itself, in this case
download_page.py, so sys.argv[1]
should be the URL of
the webpage to be saved and sys.argv[2]
the file name for
the output file. The file name can contain a location for the output file, e.g.,
mydir/somepage.html
. If a directory is specified with the
file name, the script doesn't check to ensure the directory exists and
will exit with a Python "No such file or directory" error message should
that error occur. If no directory path is included with the file name,
the directory from which the script is run will be used to store the
downloaded webpage.
The script will print error messages if the URL and output file name are
omitted from the command line. It can be run using python
./download_page.py
or ./download_page.py
, if for the latter
option you have first changed the
file permissions on the program to mark it as executable, e.g., with
chmod 755 download_page.py
.
download_page.py
[/languages/python]
permanent link
Tue, Mar 01, 2016 11:08 pm
Kiddle
My wife informed me this morning that someone had commented on a site
she visits regularly that Google is now providing a kid-friendly version
of its search engine, Kiddle. I hadn't heard of the site and when I checked
I found that the site isn't owned or operated by Google, but, instead, was
developed by someone else based on the Google Custom Search capability, i.e.,
it relies on Google's search engine, but with its own custom filters to
eliminate results that may be unsuitable for young children.
[ More Info ]
[/network/web/search]
permanent link
Privacy Policy
Contact