termname() {
echo -en "\e]1; $1 \a"
}
And if we are saying about Stackoverflow one of the most useful Vim suggestion I've ever found is this instruction to comment/uncomment a multiple lines in VIM.
Kind of my extended memory with thoughts mostly on Linux and related technologies. You might also find some other stuff, a bit of SF, astronomy as well as old (quantum) chemistry posts.
termname() {
echo -en "\e]1; $1 \a"
}
def set_account(environment):
"""set_credentials(environment) -
sets credentials for given environment/account.
"""
for i in boto.config.items(environment):
boto.config.set('Credentials', i[0], i[1])
import boto
set_account('prod')
conn = boto.connect_ec2()
set_credentials(self.args.environment)
parser.add_argument('-e', '--environment', type=str, required=True,
help="select an environment/profile to run.")
#!/bin/sh cd $(dirname $0) ./ec2.py -e prod --refresh-cache
#!/bin/bash
TMP_FILE=/tmp/current_aws
awk \
'BEGIN{a=0};\
/\['$1'\]/ {a=1};\
/access_key_id/ {if (a==1){printf "export %s=%s\n", toupper($1), $3}};\
/secret_access_key/ {if (a==1) {printf "export %s=%s\n", toupper($1), $3;a=0}}'\
~/.aws/credentials > $TMP_FILE
source $TMP_FILE
rm $TMP_FILE
while [ 1 ];
do
date;
cat /proc/loadavg;
ps -Leo state,args |
awk ' $1 ~ /(D|R)/ {state[$0]++} \
END{ for (j in state) {printf "%s - %d\n", j, state[j]}}' |
sort -k 2;
echo "---";
sleep 5;
done
$1 ~ /(D|R)/" can be useful in case of problem with total number of processes. But then the whole command should be a bit modified, so the results are sorted by number of processes. Simplified version would look like this one:while [ 1 ];
do
ps -Leo state,args |
awk ' $1 ~ /(D|R)/ {state[$0]++} \
END{ for (j in state) {printf "%d - %s\n", state[j], j}}' |
sort -n;
echo "---";
sleep 5;
done
#!/usr/bin/env python
"""Example code to use Fabric as a library.
It shows how to set up host manually.
Author: Wawrzek Niewodniczanski < main at wawrzek dot name >
"""
# import sys to deal with scripts arguments and of course fabric
import sys
import fabric from fabric.api import run, hide, env env.hosts = ['host1', 'host2']
# Main function to run remote task
def run_task(task='uname'):
"""run_task([task]) -
runs a command on a remote server. If task is not specify it will run 'uname'."""
# hide some information (this is not necessary).
with hide('running', 'status'):
run(task)
# Main loop
# take all arguments and run them on all hosts specify in env.hosts variable
# if not arguments run 'uname'
if len(sys.argv) > 1:
tasks = sys.argv[1:]
for task in tasks:
for host in env.hosts:
env.host_string = host
run_task(task)
else:
for host in env.hosts:
run_task()
#!/usr/bin/env python
"""Example code to use Fabric as a library.
It shows how to set up host manually.
Author: Wawrzek Niewodniczanski < main at wawrzek dot name >
"""
# import sys to deal with scripts arguments and of course fabric
import sys
import fabric from fabric.api import run, hide, env, execute env.hosts = ['host1', 'host2']
# Main function to run remote task
def run_task(task='uname'):
"""run_task([task]) -
runs a command on a remote server. If task is not specify it will run 'uname'."""
# hide some information (this is not necessary).
with hide('running', 'status'):
run(task)
# Main loop
# take all arguments and run them on all hosts specify in env.hosts variable
# if not arguments run 'uname'
if len(sys.argv) > 1:
tasks = sys.argv[1:]
for task in tasks:
execute(run_task, task)
else:
execute(run_task)
netstat -nt| \
awk -F':'\
'$5==80 {count[$8]++} \
END{ for (i in count) { \
cmd="host "i; \
cmd |& getline j; \
split(j, a, " "); \
printf "%40s - %d\n", a[5], count[i]}}'| \
sort -n -k 3
import multiprocessing
SIZE = 30 pool = multiprocessing.Pool(processes=SIZE) pool_output = pool.map(get_values, servers) pool.close() # no more tasks pool.join()
^old^new
to replace string old by new in last command. The only problem is that it replaces only first appearance. But there is another command replacing all string old by new:
!:gs/old/new/