PHP in the Command Line

Written by Robert Plank

There's a single line you can add to your web host's control panel that will automatically archive your content.


Ever run commands in DOS? You've used a shell. A "shell" inrepparttar computer world is a place where you enter commands and run files by name rather than clicking around different windows.

Most web hosts let you operate a shell remotely. This means that you can type commands in window on your computer, that are actually run on your web host, thousands of miles away.

I'd like you to log in to your shell now. If you can't do it by going in to DOS and typing "telnet", your web host probably uses "SSH" -- a secure shell. You'll have to ask your host how you can log in torepparttar 107759 shell, they might tell you to download a program called "PuTTY" and give instructions how to use it.

If you can't login to your shell, or aren't allowed, you'll just have to sit back and watch what I do.

Now that you're logged in, type: echo hi

Onrepparttar 107760 next line will be printed hi

Try this: date +%Y

This printsrepparttar 107761 current year. That's 2004 for me.

So what if we combinedrepparttar 107762 two? Try: echo date +%Y

Well, that doesn't work, becauserepparttar 107763 computer thinks you're trying to echorepparttar 107764 TEXT "date +%Y" instead ofrepparttar 107765 actual COMMAND. What we have to do here is surround that text in what are called "back quotes". Unix will evaluate everything enclosed in back quotes (by evaluate, I mean it'll treat that text as if it were entered as a command.)

Your back quotes key should be located onrepparttar 107766 upper-left corner of your keyboard, underrepparttar 107767 Esc button.


Type this in: echo `date +%Y`

Gives us "2004". You could even do something like this: echo `dir`

Which putsrepparttar 107768 directory listing all on one line.

But now, we put our newfound knowledge to good use. Unix has another neat feature called piping, which means "take everything you would normally output torepparttar 107769 screen here, and shove it whatever file I tell you to." So say I had something like this:

echo "hey" > test.txt

Now type "dir" and you'll see a new file, test.txt, that wasn't there before. View it offrepparttar 107770 web, or FTP it to your computer, do whatever you have to, to readrepparttar 107771 file. It should containrepparttar 107772 word "hey".

Likewise, dir > test.txt would storerepparttar 107773 directory listing into "test.txt".


But say we wanted that text file to be named according torepparttar 107774 current date. You already haverepparttar 107775 pieces to figure all that out, if you think about it. Type: date --help to get a listing of allrepparttar 107776 possible ways to representrepparttar 107777 date. The ones you want to representrepparttar 107778 year, month and day are %Y, %m, and %d (capitalization *is* important here).

This is what you want: echo `date +%Y%m%d.html`

Running this today, January 8th, 2004, results in: 20040108.html

I've just echoed this year, followed by this month and this day, with an ".html" atrepparttar 107779 end. This will be our output file.

Now, to pipe it: echo "hey" > `date +%Y%m%d.html`

If this sort of thing were to run every day, it would save "hey" to a file called 20040108.html today, and tomorrow to a file called 20040109.html, then 20040110.html, and so on.

The easy part now, is figuring out what you want archived. I use wget, which takes an option to storerepparttar 107780 output file, so we don't need to use piping. Here's an example of how to use wget to saverepparttar 107781 page "" to a file representing today's date:

wget --output-document=`date +%Y%m%d.html`


And now, to setup your crontab. I won't explain how crontabs work, just that they'rerepparttar 107782 equivalent ofrepparttar 107783 Windows Task Scheduler, which automatically run a particular command at a given date and time. The following will save to a different filename every day.

0 0 * * * wget --output-document=`date +%Y%m%d.html` > /dev/null

Keep in mind that if you want to put it in a special directory, just putrepparttar 107784 path in, i.e. change what's inrepparttar 107785 "output document" parameter to: `date +/home/user/wwwroot/`

I've pipedrepparttar 107786 output to /dev/null because wget savesrepparttar 107787 file for us, and there's no reason to do anything else withrepparttar 107788 output.

Setting Up An Internet Connection

Written by Robb Kimmer

Setting Up An Internet Connection Without loss of sanity and privacy Robb Kimmer

I know so many people who seem to have a lot of problems when they try setting up an Internet connection. Some are unfortunate enough to have beenrepparttar victim ofrepparttar 107758 endless and tedious free CDs that we all receive in our post now and again, or that fall offrepparttar 107759 front of a magazine, or that we have idly picked up from a local shop counter. The last thing you should do is use one of those to get connected. Really, you should know better! 99% ofrepparttar 107760 CDROM will be stuffed with advertising rubbish and spy-ware that gums up our computers and makes us vulnerable torepparttar 107761 advertisers onrepparttar 107762 Internet. This type of product should be banned, in my opinion. Not only is a CDROM totally unnecessary to get us connected, it is a downright infringement of our privacy. Not to mentionrepparttar 107763 fact that it will impregnate your computer with registry entries and files that will make it virtually impossible to remove without a complete re-installation of your operating system. Watch out forrepparttar 107764 spam e-mail that you will receive as soon as you log onrepparttar 107765 World Wide Web, if you have installedrepparttar 107766 CDROM software.

Besides all this, you will be trapped into using a particular web site as a search point and, to make matters worse, you will find thatrepparttar 107767 software has modified your web browser with all sorts of home-page advertising and a silly spinning logo up atrepparttar 107768 top right whererepparttar 107769 Microsoft or Netscape logo used to be. You can remove it, but it does require a registry edit, and that means strong coffee and trembling knees, even forrepparttar 107770 stout-hearted. You can create your own logo for your web browser. Make something original and pleasing to soothrepparttar 107771 stressful wait while those unnecessarily large web pages load.

How can you avoid all this hassle? Simple DIY. Everything you need to set up a connection torepparttar 107772 Internet is right there in your operating system. It doesn’t matter which operating system. Allrepparttar 107773 current Microsoft Windows™ operating systems haverepparttar 107774 necessary software installed ready for you to configure it and get connected. All flavours of Linux haverepparttar 107775 same type of setup and so does AppleMac’. The principles are allrepparttar 107776 same, butrepparttar 107777 method varies from vendor to vendor.

For this article I am going to set outrepparttar 107778 method for getting an Internet connection set up on a Windows XP Pro™ operating system. The rules and actions for Windows XP™ Home and Windows 2000 Professional™ are pretty muchrepparttar 107779 same. Windows™ ‘95/’98 and Me are very similar and so, to some extent, is Windows™ NT4 Workstation. I am not going to include Windows™ servers as it is unlikely that you would be using a server operating system in a home environment. Plus, you should not set-up an Internet connection of this sort on a network server. Server connections must be secure and protected. The configuration process is far more complex and beyondrepparttar 107780 home or casual user.

Remember, we are going to do this without any ISP CDROM disks or a safety net. Just hang on tight and followrepparttar 107781 instructions carefully and meticulously. You can’t do any great damage and if you do get into a knot, it is fairly easy to back up by simply deletingrepparttar 107782 connection. Frustration is going to berepparttar 107783 big demon in all matters concerning configuring computer services.

What you need:

You must have a computer! It must be running and you must have one ofrepparttar 107784 Microsoft Windows™ operating systems, mentioned previously. You will need a modem, internal or external, (external is best as it is easier to reset if required. An internal modem reset will need a complete computer shutdown), or an ISDN TA, (terminal adapter, needed to connect to your ISDN2e box that BT fitted). The modem/TA will be plugged intorepparttar 107785 computer via a USB or Serial port connection. You should haverepparttar 107786 correct cables and connectors supplied with your modem/TA. Look carefully atrepparttar 107787 instructions and plug everything in. Power uprepparttar 107788 modem/TA and you should see it do a power-on-self-test. Basically, allrepparttar 107789 lights onrepparttar 107790 modem/TA will flash on and off and then settle down to a power-on light and a light that indicates it’s default bandwidth, (probably 56K for a modem).

Now comesrepparttar 107791 tricky bit. You have to installrepparttar 107792 modem/TA software connection torepparttar 107793 computer. It may be that it has already been installed by your operating system’s Plug and Play technology. That is, when you plugged it in and powered it up,repparttar 107794 operating system recognised it and displayed a message telling you it had foundrepparttar 107795 new hardware and was installingrepparttar 107796 supporting software for you. If it is successful, that will save yourepparttar 107797 hassle of doing it manually. If it doesn’t you will have to go to Start>Settings>Control Panel>Add/Remove Hardware and double click onrepparttar 107798 icon. This will launchrepparttar 107799 Add/Remove Hardware Wizard. Microsoft operating systems are full of Wizards. They are supposed to be helpful? I leave you to judge that one. Once your new hardware has been detected, and providing it is a well known bit of kit and is fairly new, you should have no real hassles other than, possibly, having to supply a disk which containsrepparttar 107800 ‘drivers’ forrepparttar 107801 hardware. The drivers are code whichrepparttar 107802 operating system needs to act as a translator betweenrepparttar 107803 CPU (computer processing unit,repparttar 107804 computer chip) andrepparttar 107805 modem/TA internal software. Oncerepparttar 107806 drivers are loaded/installed you will be told all is well. If you are having problems finding a driver for your modem/TA fromrepparttar 107807 list inrepparttar 107808 hardware wizard, locaterepparttar 107809 Universal drivers and load a 56K driver. It should work fine. You can download a specific driver fromrepparttar 107810 vendor’s web site when we have you up and running further down this page.

Now you haverepparttar 107811 modem/TA installed it’s a good idea to run a quick diagnostic test to make sure it is working and there are no software problems. Go to Start>Settings>Control Panel>Modems in most Windows™ operating systems. In Windows XP™repparttar 107812 route is a bit more convoluted. You may have to navigate torepparttar 107813 Printers and Other Hardware>Phone and Modem Options (!). Once you have foundrepparttar 107814 modem icon orrepparttar 107815 appropriate icon, double click it and chooserepparttar 107816 Modems Tab. Then choose Properties and then Diagnostics Tab. You will see a button that is labelled Query Modem. Click it andrepparttar 107817 system will send a message to interrogaterepparttar 107818 modem/TA. Lights will flash onrepparttar 107819 unit and you should see a lot of strange text flow intorepparttar 107820 box onrepparttar 107821 screen. That’s it. As long as you getrepparttar 107822 text everything is fine. No text and you may have to re-installrepparttar 107823 driver orrepparttar 107824 hardware. Other information may be available in this dialog box. Such as,repparttar 107825 port thatrepparttar 107826 modem is connected to. If it’s a Serial/Com port, say Com 1, and you are having a problem, try setting it to COM 2 and try runningrepparttar 107827 diagnostics again. It usually works second time around. It is possible to set both ports as a connection. You can also choose to turn offrepparttar 107828 modem/TA speaker if you don’t want to hear that strange squawking sound that a modem/TA makes when it is conversing withrepparttar 107829 modem atrepparttar 107830 ISP.

Cont'd on page 2 ==> © 2005
Terms of Use