Archive for Newbie

man and a new one I just stumbled on….

Ok, I feel stupid, however I never realized that I could search man pages!

For those that don’t know, unix offers a built in “manual” command called “man”… sometimes it’s helpful, sometimes it’s there just for reference. It’s easy

$ man command

in this case man ls

LS(1) FreeBSD General Commands Manual LS(1)

NAME
ls - list directory contents

SYNOPSIS
ls [-ABCFGHLPRTWabcdfghiklmnopqrstuwx1] [file …]

DESCRIPTION
For each operand that names a file of a type other than directory, ls
displays its name as well as any requested, associated information. For
each operand that names a file of type directory, ls displays the names
of files contained within that directory, as well as any requested, asso-
ciated information.[and on and on]


man is a great thing, however sometimes you end up forgetting the command your using, and thats when my new little friend helps out…

$ man -k search-scring[ENTER]

This is awsome, now I can find all the insane instances of locate :) man -k locate

cfree(3) - free up allocated memory
index(3) - locate character in string
locate(1) - find filenames quickly
locate.updatedb(8) - update locate database
memchr(3) - locate byte in byte string
mmap(2) - allocate memory, or map files or devices into memory
pthread_mutex_destroy(3) - free resources allocated for a mutex
rindex(3) - locate character in string
strchr(3) - locate character in string
strpbrk(3) - locate multiple characters in string
strrchr(3) - locate character in string
strstr(3), strcasestr(3), strnstr(3) - locate a substring in a string
usbhid(3), hid_get_report_desc(3), hid_use_report_desc(3), hid_dispose_report_desc(3), hid_start_par
se(3), hid_end_parse(3), hid_get_item(3), hid_report_size(3), hid_locate(3), hid_usage_page(3), hid_
usage_in_page(3), hid_init(3), hid_get_data(3), hid_set_data(3) - USB HID access routines
whereis(1) - locate programs
which(1) - locate a program file in the user’s path

Give it a whirl!

Comments

Mysql Permissions — Quickly

Sometimes you gotta grant Mysql permissions for usernames… so here’s how I do it.

$ mysql -u root -p

Enter password: [password] [ENTER]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 14806 to server version: 4.1.11

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> insert into db values (’IP or Hostname‘, ‘DB Name‘, ‘Username‘, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘N’, ‘Y’, ‘Y’, ‘Y’);

mysql> insert into user values (’IP or hostname‘, ‘Username‘, ‘xxx’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’, ‘N’);

the XXX is where the password will exist.

mysql> update user set Password=password(’Password‘) where user=’Username‘;

Comments

SSH Keys for passwordless logins to other servers

SSH Keys are an awsome tool.. and they’ll save your fingers from typing your password 10,000 times a day. They’re also really easy to setup:

login to your main server, or home machine as the user you normally are logged in as.

username@yourserver.com [16:00:51]
[~/.ssh]: /usr/bin/ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_dsa): [ENTER]
Enter passphrase (empty for no passphrase): [ENTER]
Enter same passphrase again: [ENTER]
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:1e:00:fb:d5:57:45:20:c3 username@yourserver.com

username@yourserver.com [16:00:59]
[~/.ssh]: cat id_dsa.pub

ssh-dss [EDITED OUT HUGE TEXT HASH ] username@yourserver.com

Copy the entire output from your server to your clipboard.

Now login to the remote server you want to be able to access without a password and:

$ vi ~/.ssh/authorized_hosts

go to the bottom of the file and insert and paste the line, then [ESC] [ESC] :wq!

and give it a test

$ ssh username@remoteserver.com

Comments

tail - check the end of the file

when dealing with logs, getting to the end of a huge file is a huge pain. Thats why tail was created.

tail is on most machines and can be used as such



tail filename[ENTER]

by default that shows the last 5 lines of the file.



tail -n 1000 filename

will show the last -n # of lines.


tail also has another useful feature, which is show the log file as it’s written to:

so

tail -f filename

will stay active showing you the log file as it’s written to on the screen. You can press Control and C at the same time to break out.

Give it a try on a web log file and hit a site, you’ll see your visit!

Comments

VI Basics

OK… so basically every unix box has VI on it… however so many people are confused about it. Here are some basics:

vi filename
loads you into a weird and wonderful world of editor, but you can’t type anything. You can scroll up and down using the arrow keys generally, or J to go down and K to go up. You can move the cursor using the right and left arrow keys, or l to move left, and h to move right.

When you want to INSERT text at the point of the cursor, hit i

when your done, hit [ESC]

if you want to Append to the end of the line hit A and [ESC] to exit

to find a specific match you can do [ESC] [ESC] to make sure your out of edit mode and then

/searchstring

after you’ve found one match you can hit /[ENTER] and it will find the next match

to Quit, hit [ESC] [ESC] to make sure your out of edit mode, and then
:q[ENTER]

if you want to write the file, hit [ESC] [ESC] :w[ENTER]

You can stack commands, so [ESC] [ESC] :wq[ENTER] will write and quit vi.

There are tons of VI commands, but I’ll add more later on :)

Comments

Crond and crontab- damn it’s powerful.

While most admins know about crontab, some new folks don’t, so here is a basic primer:

crond runs on most unix machines by default and controls automated tasks for the system based on time. Most boxes have cleanup scripts that run at 4am when processor is low, and thats a good thing.

Cron has two major files, one /etc/crontab which contains system level cron entries, cleanup scripts, and things that are for the system to run, not an individual user. These are runnable as whatever user you want, however generally are root crontabs.

Cron has a funny way of dealing with time…. and thats where most people get screwed up:



the format is as such:
minute hour mday month wday who command

minute is obvious, 5 is :05 or 45 is :45 on the hour.
hour is the same.
mday is the day of the month, for example 1 is the first, 20 is the 20th.. be careful that you don’t schedule things after the 28th, not all months have it.
wday is day of the week, you can schedule 0 as sunday, 1 as monday, and so on, until you hit 6 which is saturday
who is what user it’s run under, this is NOT part of user crons (only system crons in /etc/crontab) it can be any username on the system
command is the command you want cron to run, I suggest using full paths :)


There is two other bits of cron trickery stil…

A blank is indicated by a *, not a space. This is a wildcard statement in unix, so it always matches.

The other thing to learn is scheduling multiple times. You can define multiple times either using a comma (,) such as
25,45 * * * * root /usr/libexec/atrun

To run /usr/libexec/atrun at :25 and :45 of the hour, or you can divide time, so every five minutes

*/5 * * * * root /usr/libexec/atrun


When editing crontabs you want to (as root)vi /etc/crontab and change the file, using [ESC] :wq![ENTER] to write the file and then use a HUP command to signal cron to reread it’s configuration (killall -HUP crond works, it’s a bit generic)



Users can have personal crons as well, they can be edited by doing the command
crontab -e [enter] and using [ESC]:wq![ENTER] to quit

and then using the format WITHOUT a “who” username.
an example:
*/5 * * * * /usr/libexec/atrun

To run /usr/libexec/atrun every 5 minutes.

Comments

« Previous entries · Next entries »