Tutorials - Servers > CGI/Shell Server Advanced Topics
Tutorials and FAQS: Servers: CGI/Shell Server Advanced TopicsPlease Note: This tutorial relates to the new CGI Platorm which went live at the end of June 2005
This tutorial considers some of the more advanced tasks that you can accomplish while using the CGI/Shell Server provided by PlusNet. It is designed as a follow-up to the CGI/Shell Server Basics tutorial currently available. The following subjects are covered in this tutorial:
- Downloading Files to the Server
- Uncompressing a tar.gz file
- Simple File Editing
Downloading a File using "wget"
"wget" is a command line tool used for downloading files from the internet and is available for use on the CGI platform. However, wget is not a web browser. If you wish to download files using wget, you should find the script using your usual web browser of choice, and then copying and pasting the URL from the address bar to the program you are connected to the server with.
For the purposes of this tutorial, the file being downloaded will be from a PlusNet account, used by the Tutorial Team.
To download a file from the internet, you simply specify "wget <url>" where <url> is the URL you wish to download. In this example, we are going to be using http://www.tutorialsteam.plus.com/servers/CGIshellAdvanced/tutorial.tar.gz [Note: In these examples, this should all be on one line]
| username@shellx username $ wget http://www.tutorialsteam.plus.com/servers/CGIshellAdvanced/tutorial.tar.gz --16:54:16-- http://www.tutorialsteam.plus.com/servers/CGIshellAdvanced/tutorial.tar.gz => `tutorial.tar.gz' Connecting to www.tutorialsteam.plus.com:80... connected! HTTP request sent, awaiting response... 200 OK Length: 508 [application/x-gzip] 0K 100% @ 496.09 KB/s 16:54:20 (496.09 KB/s) - `tutorial.tar.gz' saved [508/508] username@shellx username $ |
What does this mean?
| --16:54:16-- http://www.tutorialsteam.plus.com/servers/CGIshellAdvanced/tutorial.tar.gz `tutorial.tar.gz' |
16:54:16 indicates the time I started the download, the URL I am downloading follows this.
`tutorial.tar.gz' indicates that it is being downloaded to tutorial.tar.gz
| Connecting to www.tutorialsteam.plus.com:80... connected! HTTP request sent, awaiting response... 200 OK Length: 508 [application/x-gzip] |
The first line tells you which server you are connecting to,and if it was successful that it is downloading 508 bytes, and the file is a gzip'ed file.
The next line is a progress indicator, which may consist of more than one line depending on the size of the file you are downloading.
| 16:54:20 (496.09 KB/s) - `tutorial.tar.gz' saved [508/508] |
This line tells you the time it finished, the average speed, the fact the file was saved and the bytes saved/bytes expected
I want to change the name of the file that is being saved
To save the file with a different name, the easiest way is to use a text only browser called "Lynx".
So, to download the previous url to the local file mytutorial.tar.gz you would use:
| username@shellx username $ lynx http://www.tutorialsteam.plus.com/servers/CGIshellAdvanced/tutorial.tar.gz |
The screen will change to display:
| application/x-gzip D)ownload, or C)ancel |
Press D to download and a text menu will appear. Choose the "Save to Disk" option by pressing Enter and type the name you wish at the prompt and press Enter. Press q to quit, and y to confirm.
Uncompressing a tar.gz file
A .tar.gz is a compressed file, generally used on Unix/Linux operating systems, much like Zip is used on Windows.
It is possible to uncompress the file using one instruction. In this example I am going to use tutorial.tar.gz from the previous example.
| username@shellx username $ tar -xzf tutorial.tar.gz username@shellx username $ ls cgi-bin tutorial |
After executing the tar command, you are returned to the prompt. To check if the command was successful, you should have a new folder called "tutorial" listed if you run the "ls" command.
Simple File Editing
It is possible to edit files directly on the CGI server. A number of text editors are installed on the CGI/Shell Server, this tutorial looks at two of them.
For this example, I am going to use a file in the tutorial folder which was created in the previous section on Uncompressing a .tar.gz file.
First, make sure you are in the tutorial subfolder, by using the following commands.
| username@shellx username $ cd tutorial username@shellx tutorial $ ls README test.pl |
Pico
To edit the README file use pico, you would execute the following command:
| username@shellx tutorial $ pico README |
After executing the command, the screen will look like:
| UW PICO(tm) 4.0 File: README Congratulations. If you see this file, you have successfully followed the instr$ [ Read 1 line ] ^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text^T To Spell |
The reason the line ends instr$ is because when the original file was created, the sentence was typed all on the one line, which pico can not fit on the screen.
At the bottom of the screen you will noticed a lot of commands which are all written as ^LETTER, the ^ is used to symbolise the "Control" key on the keyboard, usually labled "Ctrl". To carry out one of the commands, you press Ctrl + The Letter to the right. So, to exit Pico you press Ctrl + X.
Now, lets say we wish to change "If you see this file," to "If you can see this file," we would navigate along to "see" by using the cursor keys, and type "can". To save the changes, you would then press Ctrl+O. The bottom of the screen the turns into:
| File Name to write : README ^G Get Help ^T To Files ^C Cancel TAB Complete |
To save as README, you press the Enter/Return key or you can change the name and then press Enter/Return.
Vi or Vim
To edit the README file using vi or vim (which is an enhanced version of vi), you would execute the following command:
| username@shellx tutorial $ vi README |
After executing "vi README" the file will be open on screen and will look like:
Congratulations. If you see this file, you have successfully followed the instructions in the PlusNet/Free-Online/Force9 Tutorial relating to downloading files using wget and untarring them. "README" 1L, 191C 1,1 All |
When you start vi you are in command/move mode and you type 1 or 2 char commands to move around and edit the file as follows:
space - move forward 1 char
backspace - move back 1 char
up/down arrows - move up/down 1 line
left/right arrows - move left right 1 character (this may not work, use space/backspace if it does not)
i (or INSERT key) - enter insert mode, type whatever you want including new lines etc and it will be inserted at the current cursor position, press <ESCAPE> to get back to command mode. When in insert mode, the word INSERT will appear at the bottom of the screen.
x - delete 1 character under the cursor
r - replace 1 character under the cursor, type 1 char which replaces what is under cursor
R - enter overwrite mode, type text which will replace what is under cursor, press <ESCAPE> to get back to command mode.
cw - change word, puts you in overwrite mode, type replacement text which replaces the word under the cursor- new text can be smaller or bigger than existing word length, <ESCAPE> to get back to command mode
u - undo last change, repeated u's will undo previous changes
U - undo all changes on current line
$ - move to end of line, stay in command mode.
o - insert a line after current one, you are put in insert mode, type your text then <ESCAPE> to get back to command mode.
O - insert a line above the current one, you are put in insert mode, type your text then <ESCAPE>
:w - write the changes to disk but stay in vi
:wq - write and quit, you can do the same by typing ZZ
:q! - quit and discard changes (in case you mess it up)
If you get stuck hit <ESCAPE> several times to make sure your in command mode.
With the above basic commands you should be able to create/edit text files, for the full list of commands type man vi at the $ prompt to view vi's manual pages. When viewing a man page, use space to go to the next page, b to go back a page and q to quit back to the $ prompt.
vi/Vim section updated 19/02/04 - petervaughan
Original Article by: csogilvie - Edited by: csogilvie