Useful Commands

Remote Reboot

  • net rpc shutdown -r -t 1000 -c “system is going to shutdown ” -I <ip address> -U administrator

Remote Services

  • net rpc service list -I IPADDRESS -U USERNAME
  • net rpc service stop SERVICENAME -I IPADDRESS -U USERNAME
  • net rpc service start SERVICENAME -I IPADDRESS -U USERNAME

Raid Checking

  • get the raid disk
    cat /proc/mdstat
  • check the raid status
    mdadm --detail /dev/md0
  • full disk check
    mdadm --detail /dev/md0

Directory Usage

du ./* --max-depth=0 -m | sort -nr | head -n 10

Apache Access Log - IP Address Usage

cat access.* | awk '{ print $1 }' | sort | uniq -c | sort -n

SSH Tunnel Control

  • ssh -M -S my-ctrl-socket -fnNT -L 50000:localhost:3306 jm@sampledomain.com
  • ssh -S my-ctrl-socket -O check jm@sampledomain.com
Master running (pid=3517)
  • ssh -S my-ctrl-socket -O exit jm@sampledomain.com
Exit request sent.

Memory Usage

Convert Video Files

  • MKV → MPG
    ffmpeg -i "file.mkv" -c:a copy -c:v copy "file.mp4"

Display Log Files By Revision

  • Linux -
    cat $(ls -rv /var/log/auth.log*) | grep do something or other
  • Windows -
    for /f %i in ( 'dir buncha.logs* /o:d /b' ) do cat %i | grep -i "lookingfor" >> found.txt

Testing crontab command

From serverfault.com

Add the following line to the crontab, e.g. using crontab -e

* * * * *  /usr/bin/env > /home/username/cron-env

Create a shell script which executes a command in the same environment as cron jobs run:

#!/bin/sh

. "$1"
exec /usr/bin/env -i "$SHELL" -c ". $1; $2"

Use:

run-as-cron <cron-environment> <command>

e.g.

run-as-cron /home/username/cron-env 'echo $PATH'

Note that the second argument needs to be quoted if it requires an argument. The first line of the script loads a POSIX shell as interpreter. The second line sources the cron environment file. This is required to load the correct shell, which is stored in the environment variable SHELL. Then it loads an empty environment (to prevent leaking of environment variables into the new shell), launches the same shell which is used for cronjobs and loads the cron environment variables. Finally the command is executed.

 
 commands.txt · Last modified: 2017/11/07 09:56 by bpienig
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
Recent changes RSS feed Driven by DokuWiki