Frequently used unix commands by Greenplum DBA's

Acript argument: $1 is the first argument, $2 is the second argument, and so on. The variable $0 is the script's name. The total number of arguments is stored in $#. The variables $@ and $* return all the arguments

1. route - show / manipulate the IP routing table

see also:  ip route

2. nslookup

3. ifconfig -a

4. hostname

5. ping

6. ethtool eth0

7. netstat -rn

8. top

9. vmstat

10. w

--Find out total space used by primary segment databases (excluding log files and local backup files)

[gpadmin@sachi ~]$gpssh -f $GPHOME/hosts.seg "du –h --exclude=*pg_log* --exclude=*db_dump* -s /data[12]/primary/gpseg*"

--Change owner of all tables in Public schema

for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" sachi` ; do psql -c "alter table $tbl owner to gpadmin" sachi ; done

--Move all tables from Public Schema to a specified schema.

for tbl in `psql -qAt -c "select tablename from pg_tables where schemaname='public';" sachi`; do `psql -c "ALTER TABLE $tbl SET SCHEMA sachi;" sachi`; done

DATABASES=`psql -q -c "\l" | sed -n 4,/\eof/p | grep -v rows | grep -v template0 | awk {'print $1}' | sed 's/^://g' | sed -e '/^$/d' | grep -v '|'`

11.uptime

12. ps

13. free

14. iostat

15.sar

16. mpstat

17.pmap

18. /proc file system - various kernet stats

# cat /proc/cpuinfo

# cat /proc/meminfo

# cat /proc/zoneinfo

# cat /proc/mounts

# cat /proc/version

19. lsof

Find out total space used by log files of primary segment databases

[gpadmin@sachi ~]$gpssh -f $GPHOME/hosts.seg "du –h -s /data[12]/primary/gpseg*/pg_log*"

$(date +%s)

start_time=$(date +%s)

end_time=$(date +%s)

duration=`expr $end_time - $start_time`

echo `expr $difference / 3600`:`expr "(" $difference / 60 ")" % 60`:`expr $difference % 60`

List files in current directory and its size

for i in `ls -lh|awk {'print $9,$5}'`; do echo $i; done

20. last

21. df

22. du

23. kill

24. traceroute

25. rsync

26. rpm

27. tar

28. pwd

29. lsb_rlease -a

30. uname -a  [-prints the name, version and other details about the current machine and the operating system running on it.]

Find out total space used by backup files of primary segment databases

[gpadmin@sachi ~]$gpssh -f $GPHOME/hosts.seg "du –h -s /data[12]/primary/gpseg*/db_dumps*"

Change all uppercase to lowercase with vi?

:%s/.*/\L&/

Conversely, :%s/.*/\U&/ will change all the characters to uppercase.

List all directory and subdirectory

ls -lDR | grep ':$' | head |sed -e 's/:$//'

datediff() {

 d1=$(date -d "$1" +%s)

 d2=$(date -d "$2" +%s)

 echo $(( (d1 - d2) / 86400 )) days

 }

timespent() {

 d1=$(date -d "$1" +%s)

 d2=$(date -d "$2" +%s)

 echo $(( (d1 - d2) )) seconds

 }

Date Difference function in unix - Nov 12, 2014 12:19:8 AM

Read a File Line By Line in UNIX - Oct 15, 2014 6:53:36 PM

auto start sshd at boot time - May 20, 2013 11:11:6 PM

netstat command - May 06, 2013 12:22:55 AM

ethtool  command - May 06, 2013 12:20:58 AM

ping command - May 06, 2013 12:17:32 AM

hostname command - May 06, 2013 12:15:40 AM

ifconfig command - May 06, 2013 12:14:28 AM

nslookup command - May 06, 2013 12:12:50 AM

route command - May 06, 2013 12:10:16 AM