Create file with random data and specific size

Here is a quick bash one liner to to create a file with random data and a specific file size

This command will create a 2 MB file with random contents:


$ dd if=/dev/urandom of=test.zip bs=1M count=2
2+0 records in
2+0 records out
2097152 bytes (2.1 MB) copied, 0.208422 s, 10.1 MB/s

To view the file contents use:

hexdump test.zip |less

0000000 e209 6901 5e31 3747 7c24 4643 4c5f 74e7
0000010 8b99 fabb 74fa d3ed a5f1 90d9 e751 9ead
0000020 baea bec2 b0ca 5f2b 8719 8091 bb0e f82f
0000030 bf54 1c37 d764 a3bb 00c5 1871 ab6f 2c2b
0000040 b4d1 8e8e 1eeb ee19 8c58 31e0 58da 58d5
0000050 94d0 2141 c87e 5184 a722 594c 779a aa0a
0000060 01e4 ecaf a43c b5d8 1977 07cd de20 306f
0000070 13d3 1ef1 5d7d a482 e39b 086e 00f1 defd
0000080 8ec8 ed3d 2cb2 8f60 0da5 21e1 63df 21b0
0000090 a4b4 4617 c400 d9a5 694a 83bb 54d7 3874
00000a0 8b17 bc0c 9418 b287 a8e7 0475 be9c 9412
00000b0 548a a917 a577 b0f5 2806 9c8e 1728 5b9a
00000c0 a737 0fb7 070e dde9 b0fb a616 8133 0544
...

If running the command as root, you may want to chmod the file to 777 for access if using it as a test file to upload.

Enjoy.

linux-dash

Hi,

Here is a nifty little monitoring utility with a clean GUI interface that is a drop-in, low-overhead monitoring web dashboard for a linux machine.

Monitors your server with stats on your precious hardware.

Update individual stats on demand.

xX4Y6CQ

:::Demo:::

Identifying PHP Spam

To identify PHP Spam when running PHP 5.3 or higher: (Please note the variables below are not enabled by default in php.ini) utilize the following php.ini variable to narrow down the offending script.


If you suspect there is a PHP script sending out email (and it is still doing so) try adding these two lines:

mail.add_x_header = On
mail.log = /var/log/php_mail.log

to the [mail] section of:

/usr/local/lib/php.ini

Continue reading “Identifying PHP Spam”

check-httpd.sh

Here is a quick little bash script to let you know if apache is up and running or not and will email a specific user with details.


cd /root/bin/
touch check-httpd.sh
vim check-httpd.sh

add script below to check-httpd.sh file


#!/bin/bash

FILE=apache-snapshot.txt
DIR=/root

#set this and then uncomment the mail command on 38
MAILTO=email@domain.com

SUBJECT="APACHE_DOWN-host.mydomain.com"

LOAD=`cat /proc/loadavg | awk '{print $1}' | awk -F '.' '{print $1}'`

#init file
echo "Date and Load" > $DIR/$FILE
echo `date +%F.%X` - Load: $LOAD >> $DIR/$FILE

echo "APACHE STATUS:" >> $DIR/$FILE
#capture apache status:
lynx -connect_timeout=20 -dump -width 500 http://127.0.0.1/server-status 2>&1 >> $DIR/$FILE
statusexit=$?

echo "" >> $DIR/$FILE
echo "Apache Status check return code (non-zero indicates error):" $statusexit >> $DIR/$FILE

#bare line, log entries:
echo "" >> $DIR/$FILE
echo "Last 30 lines of apache error log:" >> $DIR/$FILE
tail -n 30 /usr/local/apache/logs/error_log >> $DIR/$FILE

#if status check did not exit normally, mail file.
if [ $statusexit -ne 0 ] then
i=1
mail -s $SUBJECT $MAILTO < $DIR/$FILE fi

Then...


chmod +x check-httpd.sh
mkdir -p /var/log/httpd/
touch /root/apache-snapshot.txt
crontab -e (add cron for script)
* * * * * /root/bin/check-httpd.sh (save)
tail -f /var/log/cron

to monitor crons to make sure script is executing properly. You will also receivean email to the address noted in the script.

CIDR Notation

CIDR stands for Classless Inter-Domain Routing. CIDR was developed in the 1990s as a standard scheme for routing network traffic across the Internet.


/27      1/8th of a Class C     32 hosts
/26      1/4th of a Class C     64 hosts
/25      1/2 of a Class C       128 hosts
/24      1 Class C              256 hosts
/23      2 Class C              512 hosts
/22      4 Class C              1,024 hosts
/21      8 Class C              2,048 hosts
/20      16 Class C             4,096 hosts
/19      32 Class C             8,192 hosts
/18      64 Class C             16,384 hosts
/17      128 Class C            32,768 hosts
/16      256 Class C            65,536 hosts (= 1 Class B)
/15      512 Class C            131,072 hosts
/14      1,024 Class C          262,144 hosts
/13      2,048 Class C          524,288 hosts

 
 
Continue reading “CIDR Notation”

Setup bash_eternal_history

In order to setup eternal bash history for all users:

vim /etc/bashrc

insert

if [ "$BASH" ]; then
export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S "
export PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo "`date +'%y.%m.%d-%H:%M:%S:'`" $USER "("$ORIGINAL_USER")" "COMMAND: " "$(history 1 | cut -c8-)" >> /var/log/bash_eternal_history'
alias ehistory='cat /var/log/bash_eternal_history'
readonly PROMPT_COMMAND
readonly HISTSIZE
readonly HISTFILE
readonly HOME
readonly HISTIGNORE
readonly HISTCONTROL
fi

Then as root run the commands:

# touch /var/log/bash_eternal_history
# chmod 777 /var/log/bash_eternal_history
# chattr +a /var/log/bash_eternal_history

darkstat

http://unix4lyfe.org/darkstat/

darkstat is an ntop-workalike network statistics gatherer. It runs as a background process on a cable or DSL router, uses libpcap to capture network traffic, and has a Web interface that serves up reports of statistics such as data transferred by host, port, and protocol. It also has a neat bandwidth usage graph.

Continue reading “darkstat”