Scripting

Mass setting user passwords

Every need to change (or set) passwords for a large number of users? Something like this code snippet may help. # find all the usernames with bash logins usernames=$(cat /etc/passwd | grep bash | sed ‘s/:.*//g) for i in $usernames; do echo “somepassword” | passwd –stdin $i done

Read More
Web

MediaWiki password reset

Here’s the SQL to reset the mediawiki password of a user: use mediawikidb; update tbl_user set user_password=md5(concat(user_id,’-‘,md5(‘newpassword’))) where user_name = “Alex”; The default admin username is WikiSysop, with user_id=1, so you could do: update tbl_user set user_password=md5(concat(‘1-‘,md5(‘newadminpassword’))) where user_id=1; Here’s how you add a new user: insert into user(user_name) values (“Alex”); then set a password […]

Read More
Linux

nslookup-scan of IP-range/subnet

#!/bin/bash # nslookup-scan of IP-range # It’s possible to add more networks separated with space NETS=”192.168.0″ IPRange=”1 254″ for NET in $NETS; do for n in $(seq $IPRange); do ADDR=${NET}.${n} echo “${ADDR},`nslookup ${ADDR} | awk -F “=” ‘{ print $2 }’|sed ‘s/^[ t]*//’ | sed ‘/^$/d’ | |sed ‘s/.$//’`” done done Result 192.168.0.1,cba.infra.no 192.168.0.2,bca.infra.no 192.168.0.3,abc.infra.no […]

Read More
Scripting

Hints and Tips for general shell script programming

WARNING: this will fail if the user is playing with $0 For example using a symbolic or hard link with a unexpected name. # Simplest… # PROGNAME=`type $0 | awk ‘{print $3}’` # search for executable on path PROGNAME=`basename $PROGNAME` # base name of program # Advanced… # Script name, in what directory, and in […]

Read More
Web

Blocking Image Bandwidth Theft/Hotlinking with URL Rewriting

You can stop others from hotlinking your site’s files by placing a file called .htaccess in your Apache site root (main) directory. The period before the name means the file is hidden, so you may want to edit your file as htaccess.txt, upload it to your server, then rename the txt file to .htaccess in […]

Read More