I was working with few testers who need to change the system time occasionally on a linux box. Most of the time, they had problem while issuing the date command. Below one is a menu based shell script to update time on a linux box (xen guest in this case)
#!/bin/bash
Author : basil@
Purpose : Menu based date/time change of Linux boxes with ntpdate
Date : 04-20-2009
# Below kernel parameter is to allow xen guest take independent decision about its clock.
echo 1 > /proc/sys/xen/independent_wallclock
while :
do
clear
echo "-------------------------------------"
echo " Main Menu "
echo "-------------------------------------"
echo "[1] Show Todays date/time"
echo "[2] Change System time"
echo "[3] Show calendar"
echo "[4] Change System time to Current time"
echo "[5] Exit/Stop"
echo "======================="
echo -n "Enter your menu choice [1-5]: "
read yourch
case $yourch in
1) echo "Today is `date` , press Enter/Return key. . ." ; read ;;
2) echo "Enter new date and time [Format: MMDDHHMMYYYY]: ";read newtime ; date $newtime;echo "Today is `date`, , press Enter/Return key. . ." ; read ;;
3) /usr/bin/cal; echo "Press a key. . ." ; read ;;
4) echo "Updating to Current time..."; `/usr/sbin/ntpdate -s clock.redhat.com`;echo "Today is `date`, , press Enter/Return key. . ." ; read ;;
5) exit 0 ;;
*) echo "Opps!!! Please select choice 1,2,3 or 4";
echo "Press Enter/Return key. . ." ; read ;;
esac
done
Menu Based - Time changing Script
Tuesday, July 7, 2009 Posted by admin at 2:57 PM | Labels: Scripting
Some Excellent SED usages
**************************
SED - Stream Editor. See some good usages of SED.
http://www.megalinux.net/archives/643.html
http://sed.sourceforge.net/local/docs/emulating_unix.txt
http://sed.sourceforge.net/local/docs/An_introduction_to_sed.html
Curl Tricks
Noticed some good curl usages...Worth copying to one more page on internet.
Original Article : http://www.linux.com/articles/57715
One of cURL's most useful features is a kind of URL "glob" support, which lets you specify a pattern as part of the URL to match multiple URLs. You can give a character range in brackets, such as [A-Z] or [0-9], and you can also give a list of alternatives in braces, such as {about,blog,news}. The only trick is that if you're saving to files with the -O option, you have to give that option as many times as files you match. For example, suppose you want to grab all three versions of a manual. You'd need a command like:
$ curl -O -O -O http://example.com/docs/manual.{html,pdf,tar.gz}
For HTTP requests, you can specify HTTP 1.1 byte ranges instead of entire files -- if the server has byte ranges enabled, this option returns only the specified bytes instead of the whole file. 0 represents the beginning of the file. For example, to grab the first 100 bytes:
$ curl -r 0-99 http://example.com/
Ranges don't have to begin with zero. To get bytes 100 through 200:
$ curl -r 100-200 http://example.com/
Negative values alone work from the end of the document. To grab the last eight bytes:
$ curl -r -8 http://example.com/
The -i option precedes a given URL by the server headers. Alternately, -I outputs only the headers, which is useful for seeing the OS and Web server software that a specified site is running. It also shows the date and time of the request, content length, and type of the given URL. When the -I option is used on a FILE or FTP URL, you'll get the file size and modification time.
You can upload files by specifying them as arguments to the -T option. It supports the same kind of globbing as the URL argument:
$ curl -T index-{01-99}.html ftp://ftp.example.com/pub/incoming/
By default, file uploads are given the same name as the source files, but you can specify a new name by including it in the target URL:
$ curl -T index-mine.html ftp://ftp.example.com/pub/incoming/index-yours.html
If you need to specify a username and password, give them as arguments to the -u option, separated by a colon. To upload standard input, use the hyphen as an argument:
$ some-long-pipeline | curl -u bob:secret -T - ftp://ftp.example.com/pub/bob/results.txt
Get server metrics
cURL supports built-in runtime variables that you can use to perform ad hoc diagnostics and benchmarking, or to gather statistics about the accessibility of a given URL, site, or server (all times are given in seconds, and all sizes are in bytes):
* content_type: the Content-Type value of the file
* http_code: HTTP(S) code in the page
* http_connect: HTTP code in the proxy response
* num_connects: number of new connections made in the transfer
* num_redirects: number of redirection operations that were made
* size_download: total size of downloaded data
* size_header: total size of the headers
* size_request: total size of the request
* size_upload: total size of uploaded data
* speed_download: average download speed
* speed_upload: average upload speed
* time_connect: time from the start until the remote host connection was made
* time_namelookup: time from the start of the command until name resolution was finished
* time_pretransfer: time from the start until the file transfer was about to begin
* time_redirect: time for all redirection operations
* time_starttransfer: all pretransfer time plus the time needed to calculate the result
* time_total: time for the complete operation (to the millisecond)
* url_effective: the last URL fetched
Output any of these variables with the -w option ("write-out"), giving the variables in the format %{name} as part of a quoted string. You can include any other text as part of that string, and do simple formatting by using \n for a newline or \t for a tab. For example:
$ curl -w '\nLookup time:\t%{time_namelookup}\nConnect time:\t%{time_connect}\nPreXfer time:\t%{time_pretransfer}\nStartXfer time:\t%{time_starttransfer}\n\nTotal time:\t%{time_total}\n' -o /dev/null -s http://linux.com/
Lookup time: 0.038
Connect time: 0.038
PreXfer time: 0.039
StartXfer time: 0.039
Total time: 0.039
$
To get the amount of time between when a connection is established and when the data actually begins to be transferred, subtract the value of time_pretransfer from time_starttransfer. You can automate this by sending the output to bc with echo:
$ echo "`curl -s -o /dev/null -w '%{time_starttransfer}-%{time_pretransfer}' http://linux.com/`"|bc
cURL offers other important options you'll want to use to check for timeouts or to control the transfer speed -- it has more than 100 options in total. By specifying huge URL ranges or calling curl from a loop, you can use the commands to do simple server load testing, or check for various failures by reading the variable output -- and since curl handles forms, you can even use it to test Web application speed.
Hardware/Bios Info - Dmidecode July 09, 2008
Dmidecode helps to read biosdecode data in a human-readable format
dmidecode --type {KEYWORD / Number }
Common Keywords:
* bios
* system
* baseboard
* chassis
* processor
* memory
* cache
* connector
* slot
# Type Short Description
0 BIOS
1 System
2 Base Board
3 Chassis
4 Processor
5 Memory Controller
6 Memory Module
7 Cache
8 Port Connector
9 System Slots
10 On Board Devices
11 OEM Strings
12 System Configuration Options
13 BIOS Language
14 Group Associations
15 System Event Log
16 Physical Memory Array
17 Memory Device
18 32-bit Memory Error
19 Memory Array Mapped Address
20 Memory Device Mapped Address
21 Built-in Pointing Device
22 Portable Battery
23 System Reset
24 Hardware Security
25 System Power Controls
26 Voltage Probe
27 Cooling Device
28 Temperature Probe
29 Electrical Current Probe
30 Out-of-band Remote Access
31 Boot Integrity Services
32 System Boot
33 64-bit Memory Error
34 Management Device
35 Management Device Component
36 Management Device Threshold Data
37 Memory Channel
38 IPMI Device
39 Power Supply
Eg:
root@luttappi:~# dmidecode --type 16
# dmidecode 2.8
SMBIOS 2.4 present.
Handle 0x0029, DMI type 16, 15 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
Error Correction Type: None
Maximum Capacity: 2 GB
Error Information Handle: Not Provided
Number Of Devices: 2
root@luttappi:~#
