Tuesday, 25 October 2011

cooltechy: Prevent others from browsing your files

cooltechy: Prevent others from browsing your files: In a multiuser server environment, set diretories to these settings to prevent others from browsing your files: (read/write/execute by owner...

Prevent others from browsing your files

In a multiuser server environment, set diretories to these settings to prevent others from browsing your files: (read/write/execute by owner, & only execute by others, no read/write/execute by group)

e.g.
Read Write eXecute

Owner Access On On On
Group Access Off Off Off
Other Access Off Off On

chmod 711 /usr/home/USERNAME/
chmod 701 /usr/www/users/USERNAME/

Sunday, 23 October 2011

cooltechy: curl Examples

cooltechy: curl Examples: curl http://curl.haxx.se GET form: curl "www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK" POST form: curl -d "birthyear=1905&pre...

curl Examples

curl http://curl.haxx.se

GET form:
curl "www.hotmail.com/when/junk.cgi?birthyear=1905&press=OK"

POST form:
curl -d "birthyear=1905&press=%20OK%20" www.hotmail.com/when/junk.cgi

File Upload POST:
curl -F upload=@localfilename -F press=OK [URL]

PUT:
curl -T uploadfile www.uploadhttp.com/receive.cgi



The site might require a different authentication method (check the headers
returned by the server), and then --ntlm, --digest, --negotiate or even
--anyauth might be options that suit you.
Sometimes your HTTP access is only available through the use of a HTTP
proxy. This seems to be especially common at various companies. A HTTP proxy
may require its own user and password to allow the client to get through to
the Internet. To specify those with curl, run something like:

curl -U proxyuser:proxypassword curl.haxx.se

If your proxy requires the authentication to be done using the NTLM method,
use --proxy-ntlm, if it requires Digest use --proxy-digest.

If you use any one these user+password options but leave out the password
part, curl will prompt for the password interactively.


Use curl to set the referer field with:

curl -e http://curl.haxx.se daniel.haxx.se


User Agent:
To make curl look like Internet Explorer on a Windows 2000 box:

curl -A "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)" [URL]

Or why not look like you're using Netscape 4.73 on a Linux (PIII) box:

curl -A "Mozilla/4.73 [en] (X11; U; Linux 2.2.15 i686)" [URL]


Redirects:
To tell curl to follow a Location:
curl -L www.sitethatredirects.com

If you use curl to POST to a site that immediately redirects you to another
page, you can safely use -L and -d/-F together. Curl will only use POST in
the first request, and then revert to GET in the following operations.



Cookies:
The simplest way to send a few cookies to the server when getting a page with
curl is to add them on the command line like:

curl -b "name=Daniel" www.cookiesite.com

Curl has a full blown cookie parsing engine built-in that comes to use if you
want to reconnect to a server and use cookies that were stored from a
previous connection (or handicrafted manually to fool the server into
believing you had a previous connection). To use previously stored cookies,
you run curl like:

curl -b stored_cookies_in_file www.cookiesite.com

Curl's "cookie engine" gets enabled when you use the -b option. If you only
want curl to understand received cookies, use -b with a file that doesn't
exist. Example, if you want to let curl understand cookies from a page and
follow a location (and thus possibly send back cookies it received), you can
invoke it like:

curl -b nada -L www.cookiesite.com

Curl has the ability to read and write cookie files that use the same file
format that Netscape and Mozilla do. It is a convenient way to share cookies
between browsers and automatic scripts. The -b switch automatically detects
if a given file is such a cookie file and parses it, and by using the
-c/--cookie-jar option you'll make curl write a new cookie file at the end of
an operation:

curl -b cookies.txt -c newcookies.txt www.cookiesite.com

HTTPS:
Curl supports encrypted fetches thanks to the freely available OpenSSL
libraries. To get a page from a HTTPS server, simply run curl like:

curl https://that.secure.server.com

Certificates:
Use a certificate with curl on a HTTPS server
like:

curl -E mycert.pem https://that.secure.server.com

Custom Request Elements

Doing fancy stuff, you may need to add or change elements of a single curl
request.

For example, you can change the POST request to a PROPFIND and send the data
as "Content-Type: text/xml" (instead of the default Content-Type) like this:

curl -d "" -H "Content-Type: text/xml" -X PROPFIND url.com

You can delete a default header by providing one without content. Like you
can ruin the request by chopping off the Host: header:

curl -H "Host:" http://mysite.com

You can add headers the same way. Your server may want a "Destination:"
header, and you can add it:

curl -H "Destination: http://moo.com/nowhere" http://url.com


Debug

Many times when you run curl on a site, you'll notice that the site doesn't
seem to respond the same way to your curl requests as it does to your
browser's.

Then you need to start making your curl requests more similar to your
browser's requests:

* Use the --trace-ascii option to store fully detailed logs of the requests
for easier analyzing and better understanding

* Make sure you check for and use cookies when needed (both reading with -b
and writing with -c)

* Set user-agent to one like a recent popular browser does

* Set referer like it is set by the browser

* If you use POST, make sure you send all the fields and in the same order as
the browser does it. (See chapter 4.5 above)

A very good helper to make sure you do this right, is the LiveHTTPHeader tool
that lets you view all headers you send and receive with Mozilla/Firefox
(even when using HTTPS).

Saturday, 22 October 2011

cooltechy: Resolve "device is busy" error when doing a umount...

cooltechy: Resolve "device is busy" error when doing a umount...: I f get "device is busy" when doing a umount, e.g.: [root@server/]# umount /home/data/ umount: /home/data: device is busy To find ou...

Resolve "device is busy" error when doing a umount



If get "device is busy" when doing a umount, e.g.:

[root@server/]# umount /home/data/
umount: /home/data: device is busy


To find out who's still using the share, do a, e.g.:

[root@orion /]# fuser -u -v /home/data/

USER PID ACCESS COMMAND
/home/data/ root 15376 ..c.. vim

Friday, 21 October 2011

cooltechy: Use ls -h to show Kilobyte, Megabyte, Gigabyte, et...

cooltechy: Use ls -h to show Kilobyte, Megabyte, Gigabyte, et...: Use the -h switch when doing an ls to get a more readable filesize value (K for kilobyte, M for megabyte, G for gigabyte), e.g.: [root@s...

Use ls -h to show Kilobyte, Megabyte, Gigabyte, etc

Use the -h switch when doing an ls to get a more readable filesize value (K for kilobyte,

M for megabyte, G for gigabyte), e.g.:

[root@server backup]# ls -altrh
total 9.4G
drwxr-xr-x 2 4294967294 4294967294 4.0K Oct 6 2004 last.txt
-rw-r--r-- 1 4294967294 4294967294 4.3G Oct 6 2004 backup.tgz
-rw-r--r-- 1 4294967294 4294967294 843M Nov 23 14:31 backup_20041123.tgz
-rw-r--r-- 1 4294967294 4294967294 863M Dec 4 02:33 backup_20041204.tgz
-rw-r--r-- 1 4294967294 4294967294 5.9M Jan 17 01:55 20050117.tgz
-rw-r--r-- 1 4294967294 4294967294 928M Jan 17 02:49 backup_20050117.tgz
-rw-r--r-- 1 4294967294 4294967294 960M Feb 2 15:03 backup_20050202.tgz
drwxr-xr-x 23 root root 4.0K Feb 25 18:12 ..
drwxrwxrwx 3 root root 4.0K Apr 3 01:28 .
-rw-r--r-- 1 4294967294 4294967294 1.6G Apr 3 03:36 backup_20050403.tgz
[root@server backup]#

cooltechy: Delete a range of lines in Vim example

cooltechy: Delete a range of lines in Vim example: In vim, to delete a range of lines, e.g. lines 10 through line 290, do a: :10,290d

Delete a range of lines in Vim example

In vim, to delete a range of lines, e.g. lines 10 through line 290, do a:

:10,290d

cooltechy: Rename file starting with a dash(-)

cooltechy: Rename file starting with a dash(-): If having problem renaming a file that starts with a dash: Since the file name begins with a '-' it looks like an option to the command. ...

Rename file starting with a dash(-)

If having problem renaming a file that starts with a dash:

Since the file name begins with a '-' it looks like an option to the
command. You need to force it to not look like an option. Put a ./
in the front of it. Or give it the full file name path. Or tell the
command you are through with options by using the double dash to end
all option processing. This is common to most traditional UNIX
commands.

cp ./* /some/folder
cp -- * /some/folder

And the same for other utilities too.

mv ./-stuff differentstuff
mv -- -stuff differentstuff

Tuesday, 18 October 2011

ulimit example



[root@server conf]# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
pending signals (-i) 1024
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 4095
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

[root@server conf]# ulimit -a | grep files
open files (-n) 1024

Change (example of increasing to 5000 files):

ulimit -n 5000