Archive

Archive for August, 2010

Video / Foto

August 25th, 2010 No comments

ffmpeg är ett trevligt kommandoradsprogram. För att koda om en AVCHD-fil till DVD-kompatibel MPEG kan man skriva:

ffmpeg -i "/home/test/nas/AVCHD/20100101 (Test smalfilm via dörr).m2ts" \
-croptop 100 -cropbottom 100 -cropleft 300 -cropright 300 -target pal-dvd \
-aspect 4:3 -deinterlace test43.mpg

Om man har MTS filer från en Sony AVCHD kamera kan man behöva specificera ljud och video codec. Man kan även specificera DVD som utformat och antalet processorkärnor som ska användas vid kodningen. Exempel:

ffmpeg -i 00000.m2ts -vcodec libxvid -b 18000k -acodec libmp3lame -ac 2 \
-ab 320k -deinterlace -s 1440x1080 -target pal-dvd -threads 4 output.mpg

Behöver man klippa bort överbliven bild eller ljud från AVCHD kan man använda:

ffmpeg -i in.MTS -vcodec copy -acodec copy -shortest -f mpegts 'ut.MTS'

Och ett exempel på att koda om DV video till DVD. Använd -t “hh:mm:ss” för att begränsa längden på filmen och -ss “hh:mm:ss” för att hoppa över början av filmen:

ffmpeg -i 'in.avi' -deinterlace -target pal-dvd -ss "00:54:18" out.mpg

Ytterligare ett exempel för att koda om en OGV-fil från “Desktop Recorder” till mpeg4 inbäddat i en AVI för att kunna ladda upp till YouTube:

ffmpeg -i out.ogv -y -b 4000k -minrate 4000k out.avi

Vill du koda om en AVCHD film till Adobe Flash SWF kan du skriva:

ffmpeg -i '/mnt/nas/AVCHD-Klar/20100723 (Aiya & Noah).m2ts' -f avm2 \
 -vcodec flv -ar 44100 -y noah.swf

För att kapa olika längd på ljud och bild, samt koda en AVCHD film till MP4 och skala om den till lämpligt webbformat:

ffmpeg -i "00055.MTS" -s 480x270 -b 5000k -deinterlace -shortest 00055p.mp4

Create videos for VideoJS player

Ref: http://videojs.com/

To create videos playable by most browsers from 1920×1080 AVCHD movies (stored using 1440×1080), compile ffmpeg (see below) and use:

ffmpeg -i A.MTS -deinterlace -b 1000k \
-s 640x360 A.webm
ffmpeg -i A.MTS -deinterlace -b 1000k \
-s 640x480 A.ogg
ffmpeg -i A.MTS -deinterlace -b 1500k \
-s 640x480 A.mp4

As you can see, the different formats needs different scaling, and mp4 needs more bandwidth to produce a decent video quality.

If you want to create thumbnails for your videos you can use:

ffmpeg  -itsoffset -4  -i test.avi -vcodec mjpeg -vframes 1 -an \
-f rawvideo -s 320x240 test.jpg

Or if you simply want to grab the first frame of the movie:

ffmpeg -i A.MTS -vframes 1 -an -s 640x360 A.jpg

To add the movie and thumbnail in WordPress with VideoJS player (remove the space after the first):

[ video mp4="http://xpro.se/video/00037-G3.mp4"
 ogg="http://xpro.se/video/00037-G3.ogg"
 webm="http://xpro.se/video/00037-G3.webm"
 poster="http://xpro.se/video/00037-G3.jpg"
 width="640" height="360"]

More examples how to encode to several bitrates:

ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 212x120 -y -strict experimental -acodec aac -ab 96k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre ipod320 -r 24 -g 48 -b 85000 -level 30 -threads 64 BigBuckBunny_175k.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 320x180 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre ipod320 -r 24 -g 48 -b 200000 -threads 64 bigbuckbunnyiphone_320.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 640x360 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre ipod640 -r 24 -g 48 -b 520000 -threads 64 bigbuckbunnyiphone_640.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 320x180 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre main -r 24 -g 48 -b 270000 -threads 64 bigbuckbunny_400.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 480x270 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre main -r 24 -g 48 -b 570000 -threads 64 bigbuckbunny_700.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 720x406 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre main -r 24 -g 48 -b 1000000 -threads 64 bigbuckbunny_1100.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 1024x576 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre main -r 24 -g 48 -b 1200000 -threads 64 bigbuckbunny_1300.mov
ffmpeg -i big_buck_bunny_1080p_stereo.avi -s 1080x608 -y -strict experimental -acodec aac -ab 128k -ac 2 -ar 48000 -vcodec libx264 -vpre default -vpre main -r 24 -g 48 -b 1400000 -threads 64 bigbuckbunny_1500.mov

Om du behöver stöd för MP3 och andra icke-öppna format kan du kompilera ffmpeg själv: HOWTO: Install and use the latest FFmpeg and x264

If you have this error when compiling ffmpeg:
ERROR: libvpx encoder version must be >=0.9.6
Download and compile the libvpx source before compiling ffmpeg:
http://code.google.com/p/webm/downloads/list
Then do make && install

Eller så kan du hämta en färdigkompilerad variant (se option C): HOWTO: Easily enable MP3, MPEG4, AAC, and other restricted encoders in FFmpeg

Nautilus script for Gnome users

Install the nautilus-scripts

after that go to: ~/.gnome2/nautilus-scripts and create a file called MTStoAVI, and put the following content in it:

#!/bin/bash
for a in `ls *.MTS` ; do
ffmpeg -i $a -acodec libmp3lame -ac 2 -ab 320k \
-deinterlace `echo "$a" | cut -d'.' -f1`.avi ; done
exit

after that type:

chmod +x ~/.gnome2/nautilus-scripts/MTStoAVI

Now open Nautilus and enter the directory with the MTS files, right-click anywhere and select: Scripts -> MTStoAVI
All your MTS files will be converted to AVI.

Fånga DV-video via FireWire 1394

För att använda FireWire kan du kolla så Linux ser enheten. Kolla sedan så raw1394 modulen är laddad och ladda in denna om så inte är fallet. Sen måste man ge läs/skrivrättigheter till mappen för 1394-enheten. Sen ska det funka att t.ex. hämta video från en Panasonic NV-GS50 via FireWire till Kino (som är ett program för att redigera DV-video).

dmesg
lsmod
sudo modprobe raw1394
lsmod
cd /dev
sudo chmod 777 raw1394

Konvertera RAW foton

RawTherapee är ett program för att hantera RAW-bilder.

http://code.google.com/p/rawtherapee/wiki/MercurialHowto

http://mercurial.selenic.com/

Categories: Linux Tags:

Bash skript exempel

August 19th, 2010 No comments

Skicka epost med diskutrymme (awk, case)

awk returnerar den femte kolumnen från df.
grep -v exkluderar raden med Use
sort -n sorterar siffror i stigande ordning
tail -1 returnerar sista raden som i detta fall är det högsta talet p.g.a. sort
cut -d väljer fältavgränsare, -f1 väljer fält nr 1, minustecknet på slutet anger att hämta indatat från standard-ut-enheten (istället för från en fil).

#!/bin/bash

# This script does a very simple test for checking disk space.

space=`df -h | awk '{print $5}' | grep % | grep -v Use | sort -n | tail -1 \
| cut -d "%" -f1 -`

case $space in
[1-6]*)
 Message="All is quiet."
 ;;
[7-8]*)
 Message="Start thinking about cleaning out some stuff.  \
There's a partition that is $space % full."
 ;;
9[1-8])
 Message="Better hurry with that new disk...  One partition is $space % full."
 ;;
99)
 Message="I'm drowning here!  There's a partition at $space %!"
 ;;
*)
 Message="I seem to be running with an nonexistent amount of disk space..."
 ;;
esac

echo $Message | mail -s "disk report `date`" anny

Skicka epost när viss text finns på webbsida

wget http://domain.com/file.html
grep -w Offline file.html
if [ $? -eq 0 ]
then
 mailx -s "Offline found" user@yourdomain
fi
rm file.html

Lista bara aktiva processer

Use ps, grep for the process name, then only select the lines where the 8th field starts R or S:

ps aux | grep process | awk '$8 ~ /^[RS]/'

If you want to limit the process name search to just the first part of the command (the process name itself) and not mistakenly match one of the parameters or other parts of the “ps” output, then:

ps aux | awk '$11 ~ /'"process"'/ && $8 ~ /^[RS]/'

(careful with the quotes round “process”)

Döda alla processer för en applikation

kill `ps -A|grep myapp|awk {'print $1'}`

eller

killall myapp

Starta om Apache process automatiskt via cron

Something like the following should do, just change 127.0.0.1 to you Web servers IP and possible tweak the /etc/init.d/apache* script name:

# Every hour ensure Apache is running and responsive, else START and / or RESTART apache.

01 * * * * (((ps -ef | grep -v grep | grep -q 'bin/http') ||
 /etc/init.d/apache* start) && (wget -qO /dev/null http://127.0.0.1/ ||
 /etc/init.d/apache* restart)) 2>&1 >/dev/null

Skapa array av strängar

myarray=(`ifconfig eth0`)
mymac=${myarray[5]}

Byta mappsökvägar

Use this script to search in all your tomcat sub folders for files that contain the old folder location. Change “/old/folder/location” to the correct location, then run it in the tomcat folder.

for  i in `find ./ -type f -name "*"`; do T=`cat $i | \
 grep  "/old/folder/location"`; if [ "$T" != "" ]; then \
 echo $i; echo $T; echo  ""; fi; done

Leta filer innehållande viss text

The following lists files containing a string  ignoring case:

grep -irl STRING *

Alternate method:

grep -i "STRING" `find . -name "*.txt" -print`

Lista storleken på mappar

You can use the command df -h to check if your drives are full. Then you can use the command du -hs {directory} to check the size of a directory in the hard disk.

To check all directories from root level, get root access with su (CentOS / Red Hat), then use the command:

du -hsc /*

or

find / -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \;

In Ubuntu / Debian use sudo in front of the command to get root access.

Skript för att begränsa antalet instanser av ett program

There is no built-in way in CVS to limit the number of process instances. You could help yourself with a little trick:

# rename cvs, adapt the path if necessary
 mv /usr/bin/cvs /usr/bin/cvs.bin

Create a script that will run CVS, named /usr/bin/cvs

————— >8 —————

#!/bin/bash

lockfile=/var/lock/cvs_instances.lock
max_instances=5

# get number of running instances
 if [ -r $lockfile ]; then
 num_instances=`awk '{printf $1}' $lockfile`
 else
 num_instances=0
 fi

# check if max is reached
 if [ $num_instances -lt $max_instances ]; then
 # if not, increase the number by 1
 awk '{printf("%d",$1+1)}' $lockfile >$lockfile
 # run the real cvs binary with all parameters passed to the script
 exec /usr/bin/cvs.bin "$@"
 # and decrease the number of running instances after the cvs has exited.
 awk '{printf("%d",$1-1)}' $lockfile >$lockfile
 fi

————— >8 —————

# Make sure the script has the right permissions:
chown root:root /usr/bin/cvs
chmod 0744 /usr/bin/cvs

Skript för att processa alla filer i en katalog

Skript som kopierar filer som saknas från hårddisken till en USB-pinne:

for file in ~/Documents/music/*; do 
        if [ -e /media/sdc1/"$file" ]; then
                cp $file /media/sdc1/$file
        fi
done

Ett annat exempel:

find ~/Documents/music -type f -execdir env 'file={}' \
 bash -c 'if ! test -e "/media/sdc1/$file"; then \
 cp "$file" "/media/sdc1/$file"; fi'  \;

Följande skript kodar om alla *.ogv-filer i en mapp till avi-filer.

#!/bin/bash

directory=~/Bilder/

while read file; do
 echo ”Processing: $file”
 mencoder ”$file” -ofps 23.976 -ovc lavc -oac mp3lame -lameopts abr:br=56 \
 -o ”$file.avi” done < <(find "$directory" -iname '*.ogv' -print)

Script för att packa upp alla RAR-filer i mapp

#!/bin/bash
#
if [ $# = 0 ]; then
 echo "$0 dir/"
 exit 0
fi
dirlist=$(ls -d $1*/)
dir2list=$(ls -d $1*/*/)
for d in ${dirlist} ${dir2list}; do
 echo "Thinking about $d ..."
 if [ -d "$d" ]; then
  echo "Yeah a directory"
  # First look for *.rar, to unrar
  rarcount=$(ls "${d}"/*.rar | wc -l)
  if [ $rarcount = 1 ] ; then
   echo "Unpacking rar..."
   unrar x -o- -inul "${d}/*.rar" $d
   if [ $? = 0 ]; then
    echo "OK."
    rm $d/*.r??
   else
    echo "FAILED: ${d}"
   fi
  elif [ $rarcount > 1 ] ; then
   part1rarcount=$(ls "${d}"/*.part1.rar | wc -l)
   part01rarcount=$(ls "${d}"/*.part01.rar | wc -l)
   part001rarcount=$(ls "${d}"/*.part001.rar | wc -l)     
   if [ $part1rarcount = 1 ] ; then
    echo "Unpacking rar..."
    unrar x -o- -inul "${d}/*.part1.rar" $d
    if [ $? = 0 ]; then
     echo "OK."
     rm $d/*.rar
    else
     echo "FAILED: ${d}"
    fi
   fi
   if [ $part01rarcount = 1 ] ; then
    echo "Unpacking rar..."
    unrar x -o- -inul "${d}/*.part01.rar" $d
    if [ $? = 0 ]; then
     echo "OK."
     rm $d/*.rar
    else
     echo "FAILED: ${d}"
    fi
   fi
   if [ $part001rarcount = 1 ] ; then
    echo "Unpacking rar..."
    unrar x -o- -inul "${d}/*.part001.rar" $d
    if [ $? = 0 ]; then
     echo "OK."
     rm $d/*.rar
    else
     echo "FAILED: ${d}"
    fi
   fi
  else
   echo "No rars"    
  fi # if unrar
 fi
 echo "next directory"
done
#

Kommando för att lägga till ‘noauto’ i textfil

sudo sed -i 's/ttl=5/noauto,ttl=5/' /etc/fstab

Köra kommandon för flera användare

Another (possibly more elegant) way to do this is allow the users to run a script using sudo.  Save the attached code into /bin/su-wrap and chmod it to 700.

Your sudoers file then becomes just this:
User_Alias ADMIN = a, b, c
ADMIN ALL = (ALL) /bin/su-wrap

In my case, I’m using foo1 and foo2 as “ADMIN” users, and allowing either of them to switch to the other.  You can change the 2nd lline of the su-wrap script to list whatever users you want your admins to be able to su over to.  Using your example, you’d put:
ALLOWED_USERS=”functional1

functional2″.

Testing:
foo1@npx1600734:~ $ sudo su-wrap – foo2
Password:
Executing: /bin/su – foo2
foo2@npx1600734:~ $ exit
foo1@npx1600734:~ $ sudo su-wrap foo2
Executing: /bin/su foo2
foo2@npx1600734:~ $

#!/bin/sh
ALLOWED_USERS="foo1 foo2"
USING_ENV=0
if [ "$1" = "-" ]; then
  USING_ENV=1
  shift
fi
if [ $# -ne 1 ]; then
  echo "Usage: su-wrap [-] username" >&2
  exit 1
fi
for i in $ALLOWED_USERS; do
  if [ $1 = $i ]; then
    if [ $USING_ENV -eq 1 ]; then
      CMD="/bin/su - $i"
    else
      CMD="/bin/su $i"
    fi
    echo "Executing: $CMD"
    $CMD
    break
  fi
done

To automatically check if the IP’s changed

You can add a check script and run it with cron. To add an entry to cron, use (run it as root):

# crontab -e

To check the IP every hour, you can use (first press “i” to enter INSERT mode in vi):

0 * * * * /root/chkip.sh

Then save the file (ESC and the keys “:wq” + ENTER).

Create the script with

# vi /root/chkip.sh

and paste in the attached code.

After this you’d have to set the X-bit on the script to be able to run it:

# chmod u+x /root/chkip.sh

#!/bin/sh

fileip=/tmp/oldip.txt

touch $fileip
oldip=`awk '{printf$1}' $fileip`
newip=`/sbin/ifconfig ppp0|awk '{if(NR==2)printf$2"\n"}'`
if [ "$newip" != "$oldip" ]; then
 echo $newip|mail -s ip yourname@yourdomain.com
 echo $newip > $fileip
fi
Categories: Bash, Linux Tags:

Synka filer LFTP / RSync / rm

August 19th, 2010 No comments

För att synkronisera filer och kataloger mellan två maskiner kan man använda RSync eller LFTP.

RSync

RSync använder deltakopiering och ett eget protokoll så detta kräver att båda maskinerna som ska synka har programmet installerat. Man kan montera en mapp mot t.ex. en FTP server och synka via RSync men det funkar inte stabilt enligt många rapporter.

Ex. på skript för att synka filer mellan två hårddiskar. Kopierar allt i ‘Data’-mappen till ‘sdt1’ och skapar där mappen ‘Data’:

RCMD=”rsync -av –delete –timeout=300″
DESTPATH=”/share/external/sdt1/”
SOURCEPATH=”/share/Public/Data”
$RCMD $SOURCEPATH $DESTPATH

Här är ett annat skript som lagrar backuper uppdelat per datum och tar snapshots:

#!/bin/bash
DATE=$(date %Y%m%d)
TARGET=/my/backup/device
SNAP=${TARGET}/snap
mkdir -p ${TARGET}/${DATE}
mkdir -p ${SNAP}

# main backup
rsync -avz /source/* /${TARGET}/${DATE}/

# do "snapshot" if successful

if [ $? -eq 0 ]; then
tar -zcf ${SNAP}/${DATE}.tar.gz ${TARGET}/${DATE}
else;
echo "didnt work"
fi

Ett alternativ kan vara att använda DeltaCopy som dock bara har klient för Windows: http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp

LFTP

LFTP synkroniserar två maskiner via FTP protokollet. Det klarar även en del andra protokoll, men inte RSync eller deltakopiering. Det är dock skrivit för att vara en stabil lösning som klarar nätverksfel som ostabila kopplingar. Det finns en konfigurationsfil som heter ” lftp.conf “. Bra inställningar i denna kan vara:

set ftp:charset “iso-8859-1”
set dns:max-retries 2
set net:max-retries 2
set net:timeout 10

Detta förhindrar en oändlig låsning om FTP servern på destinationsmaskinen är nere samt ställer in åäö-stöd ifall FTP server inte hanterar detta vilket t.ex. är fallet om man ska spegla (synkronisera) en mapp från ett Fujitsu Q700 NAS (samma som QNAP TS-219P) till en Tvix HD-6500 mediaspelare.

Schemaläggning av jobb

Det kan vara lämpligt att schemalägga synkroniseringsjobben. Detta görs lämpligen med ” cron “. För att lägga in ett jobb i ett Fujitsu Q700 NAS gör man följande:

  1. Logga in via SSH mot NAS’et.
  2. Kör ” vi /etc/config/crontab ” och gå in i insert-läget (genom att trycka ” i “).
  3. Lägg till raden ” 0 20 * * * /share/Public/lftp_backup.sh ” sist i filen.
  4. Avsluta vi med tangenterna ” Esc : wq ” och tryck Enter.
  5. Kör ” crontab /etc/config/crontab ” för att verkställa ändringen.

Nu kommer synkroniseringen att ske varje dag kl 20:00. Men först måste du lägga in skriptet som utför synkroniseringen. Följande kommandon i ett Bash skript kan användas för att starta en synkronisering:

#!/bin/bash
#
# *** LFTP SYNC — Tobias Holm 2010-08-19
#
# This script uses lftp to mirror files
# from a local dir to a remote FTP server.
#
# The Script also logs the transfer time.
# For automated backup add script to crontab.

#— Setup Variables —

SOURCEPATH=”/pub/source/”
DESTPATH=”/pub/backupserver/source”
DESTSITE=”ftp://srv:pass@ipaddress”
# If DESTPATH ends with a slash, the source base name
# is appended to target directory name.
LOCKFILE=”/tmp/lftp_mirror_cron.lock”
LOGFILE=”/var/log/lftp_mirror.log”
STARTTIME=$(date +”%s”)

#— Verfiy the last lftp is not still running —

if [ -f $LOCKFILE ]; then
ERRORTIME=$(date +”%d/%b/%Y:%H:%M:%S %Z”)
echo “[$ERRORTIME] WARNING lftp_mirror_cron.lock exists, aborting…” >> $LOGFIL
exit 1
fi

#— If it finished, create a new lock file —

touch $LOCKFILE

#— The lftp command (for explanation type lftp –help) —

echo “Running lftp…”
/share/MD0_DATA/.qpkg/Optware/bin/lftp -c “open -e \”mirror -Rev –delete-first

#— Log how long it took the script to run —

DONE=$(date +”%d/%b/%Y:%H:%M:%S %Z”)
STOPTIME=$(date +”%s”)
SECONDS=$(($STOPTIME – $STARTTIME))
echo “[$DONE]finished: – Tranfer took:$(((SECONDS/60)/60)) hours $(((SECONDS/60)

# — Remove lock file —

rm -f $LOCKFILE

# — END —

Radera filer med viss filändelse via Bash

T.ex. om du vill radera alla *.modd filer (OBS! en nolla efter -print och xargs nedan):

find /src -iname *.modd -type f -print0 | xargs -0 /bin/rm -f

Categories: Bash, Linux Tags:

En samling VBS skript

August 17th, 2010 No comments

'______________________________________________________________________________________
' SKRIPT FÖR ATT KONFIGURERA LOTUS NOTES 8.5.1
'
' v1.00 2010-06-21 Första versionen /Tobias Holm
' v1.01 2010-06-23 Klarar nu frånvaro av NOTES.INI + skapande av mapp /Tobias Holm
'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
On Error Resume Next

‘ Hämta inloggad användare & datornamn
Set oNetwork = WScript.CreateObject(“WScript.Network”)
sUSERID = oNetwork.UserName
sWKSTA = oNetwork.ComputerName
‘ Hämta fulla namnet på användaren
sDomain = oNetwork.UserDomain
sADSPath= sDomain & “/” & sUSERID
Set oUser = GetObject(“WinNT://” & sADSPath & “,user”)
sFULLNAME = oUser.FullName

‘ Hämta TEMP-mapp
Set oShell = WScript.CreateObject(“WScript.Shell”)
sTemp = oShell.ExpandEnvironmentStrings( “%TEMP%” )

lRet = Logg(sTemp, “\KonfigNotes.LOG”, “————————————-“)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Konfigurerar Notes 8”)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “User: ”  & sUSERID)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Name: ”  & sFULLNAME)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Comp: ”  & sWKSTA)

‘ Kolla programmapp
sDPF = RegRead(“HKLM\Software\Microsoft\Windows\CurrentVersion”, “ProgramFilesDir”)

‘ Kolla var Notes.EXE finns
sRet = RegRead(“HKLM\SOFTWARE\Classes\.nsf\shell\Open\Command”, “”)
sNPATH = Mid(sRet, 2, InStr(sRet, “\notes.exe”)-2)

‘ Kolla OM Notes.EXE finns
Set oFSO = CreateObject(“Scripting.FileSystemObject”)
If Not oFSO.FileExists(sNPATH & “\nlnotes.exe”) Then
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Hittar inte ” & Chr(34) & _
sNPATH & “\nlnotes.exe” & Chr(34))
WScript.Quit(0)
End If

‘ Kolla var Notes datafiler finns. WinXP
sDLS = RegRead(“HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”, “Local Settings”)
If sDLS = “” Then
‘ eller Win7
sDLS = RegRead(“HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders”, “Local AppData”)
End If
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Local AppData ” & Chr(34) & _
sDLS & Chr(34))

‘ Skapa Notes datamapp om den inte finns
lRet = MkDir(sDLS & “\Application Data\Lotus\Notes\Data”)

sID = sUSERID & “.id”
sDPATH = sDLS & “\Application Data\Lotus\Notes\Data”
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Letar datafiler i ” & Chr(34) & _
sDPATH & Chr(34))

‘ Kolla om vi ska konfigurera NOTES.INI
bConfig = False
If oFSO.FileExists(sDPATH & “\notes.ini”) Then
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Kollar om NOTES.INI konfig read är utförd”)
If ReadINI(sDPATH & “\notes.ini”, “ITService”, “Config”) <> “Yes” Then
bConfig = True
End If
Else
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “NOTES.INI finns inte”)
bConfig = True
End If
If bConfig = True Then
‘ Ta en säkerhetskopia på befintlig ID-fil
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Säkerhetskopierar befintlig ID-fil”)
oFSO.CopyFile sDPATH & “\” & sID, _
sDPATH & “\” & sUSERID & “.föreAutoConfig.id”

‘ Kopiera in en ny ID-fil
sSrc = “\\server\idfiler\” & sID
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Letar ” & sSrc)
If oFSO.FileExists(sSrc) Then
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Hittade ID ” & Chr(34) & _
sSrc & Chr(34))
oFSO.CopyFile sSrc, sDPATH & “\” & sID, True
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Kopierar ” & sSrc & ” -> ” & sDPATH & “\” & sID)
End If

sSrc = “M:\Backup ” & sWKSTA & “\NOTES\” & sID
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Letar ” & sSrc)
If oFSO.FileExists(sSrc) Then
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Hittade ID ” & Chr(34) & _
sSrc & Chr(34))
oFSO.CopyFile sSrc, sDPATH & “\” & sID, True
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Kopierar ” & sSrc & ” -> ” & sDPATH & “\” & sID)
End If

‘ Kollar om ID-fil finns, avsluta om filen inte finns
If Not oFSO.FileExists(sDPATH & “\” & sID) Then
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Hittade ingen ID!”)
WScript.Quit(0)
End If

sX = sTEMP & “\notesini.txt”
WriteINI sX, “Notes”, “Username”, sFULLNAME & “/Company”
WriteINI sX, “Notes”, “KeyfileName”, sDPATH & “\” & sID
WriteINI sX, “Notes”, “Domino.Name”, “server”
WriteINI sX, “Notes”, “Domino.Address”, “server”
WriteINI sX, “Notes”, “Domino.Port”, “TCPIP”
WriteINI sX, “Notes”, “Domino.Server”, “1”
WriteINI sX, “Notes”, “AdditionalServices”, “0”
WriteINI sX, “Notes”, “Replication.Schedule”, “1”

‘ Ta en säkerhetskopia på NOTES.INI
oFSO.CopyFile sDPATH & “\notes.ini”, sDPATH & “\notes.föreAutoConfig.ini”
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Konfigurerar Notes.INI”)

‘ Aktivera automatisk Notes konfigurering
sX = sDPATH & “\notes.ini”
WriteINI sX, “Notes”, “ConfigFile”, sTEMP & “\notesini.txt”
WriteINI sX, “Notes”, “IM_NO_SETUP”, “1”
WriteINI sX, “Notes”, “NAMES”, “names.nsf, companyadressbook.nsf”
WriteINI sX, “Notes”, “ExitNotesPrompt”, “1”
WriteINI sX, “Notes”, “MAXIMIZED”, “1”
WriteINI sX, “Notes”, “UserInterface”, “sv”
‘ Slå upp namn i alla adressböcker
WriteINI sX, “Notes”, “LocAllExhaustiveNameLookup”, “1”
‘ Svensk stavningskontroll
WriteINI sX, “Notes”, “SPELL_LANG”, “1053”
WriteINI sX, “Notes”, “SPELL_PREFERENCES”, “9”

‘ Flagga att automatisk Notes konfigurering är genomförd
WriteINI sX, “ITService”, “Config”, “Yes”
Else
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Gjorde ingen NOTES.INI konfig!”)
End If

lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Klart!”)
WScript.Quit(0)

‘______________________________________________________________________________________
‘ SKAPA MAPP REKURSIVT / Tobias Holm 2010-06-21

‘ Ex: lRet = MkDir(“C:\TEMP\UNDERMAPP”)
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function MkDir(x_sMapp)
Set x_oFSO = CreateObject(“Scripting.FileSystemObject”)

x_lPos = 4
x_lFound = InStr(x_lPos, x_sMapp, “\”)
While x_lFound > 0
x_sFolder = mid(x_sMapp, 1, x_lFound-1)
If Not x_oFSO.FolderExists(x_sFolder) Then
x_oFSO.CreateFolder(x_sFolder)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Skapade mapp ” & Chr(34) & _
x_sFolder & Chr(34) & ” – Err:” & Err)
End If
x_lPos = x_lFound+1
x_lFound = InStr(x_lPos, x_sMapp, “\”)
Wend
If Not x_oFSO.FolderExists(x_sMapp) Then
x_oFSO.CreateFolder(x_sMapp)
lRet = Logg(sTemp, “\KonfigNotes.LOG”, “Skapade mapp ” & Chr(34) & _
x_sMapp & Chr(34) & ” – Err:” & Err)
End If
If Err Then
MkDir = Err.Description
Else
MkDir = 0
End If

Set x_oFSO = Nothing
End Function

‘______________________________________________________________________________________
‘ LÄS REGISTRET / Tobias Holm 2010-06-17

‘ Klarar REG_SZ och DWORD
‘ Ex: lRet = RegRead(“HKCU\Software\Intel”, “Main”)
‘ Returnerar “~err” om inte Reg-root specificeras eller vid läsfel.
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegRead(x_sPath, x_sKey)
‘ Search for Reg-root
x_Root = 0
Select Case Left(x_sPath, 4)
Case “HKCU”
x_Root = &H80000001
Case “HKLM”
x_Root = &H80000002
End Select

If x_Root <> 0 Then
Err.Clear
x_sValueD = “”
x_strComputer = “.”
Set x_oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
x_strComputer & “\root\default:StdRegProv”)

x_sPath = Right(x_sPath, Len(x_sPath)-5)
x_oReg.GetStringValue x_Root, x_sPath, x_sKey, x_sValue
x_oReg.GetDWORDValue x_Root, x_sPath, x_sKey, x_sValueD

If x_sValueD <> “” Then
x_sValue = x_sValueD
End If

If Err = 0 Then
RegRead = x_sValue
Else
RegRead = “~err”
End If
Else
RegRead = “~err”
End If
End Function

‘______________________________________________________________________________________
‘ SKRIV TILL REGISTRET / Tobias Holm 2010-06-17

‘ Klarar REG_SZ och DWORD
‘ Ex: lRet = RegWrite(“HKCU\Software\Intel”, “Main”, “KALLE”, “REG_SZ”)
‘ Ex: lRet = RegWrite(“HKCU\Software\Intel”, “Count”, “35”, “DWORD”)
‘ Returnerar “~err” om inte Reg-root specificeras. Vid skrivfel returneras felkoden.
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function RegWrite(x_sPath, x_sKey, x_sValue, x_sType)
‘ Search for Reg-root
x_Root = 0
Select Case Left(x_sPath, 4)
Case “HKCU”
x_Root = &H80000001
Case “HKLM”
x_Root = &H80000002
End Select

If x_Root <> 0 Then
Err.Clear
x_strComputer = “.”
Set x_oReg=GetObject(“winmgmts:{impersonationLevel=impersonate}!\\” &_
x_strComputer & “\root\default:StdRegProv”)

x_sPath = Right(x_sPath, Len(x_sPath)-5)
Select Case UCase(x_sType)
Case “REG_SZ”
x_oReg.SetStringValue x_Root, x_sPath, x_sKey, x_sValue
Case “DWORD”
x_oReg.SetDWORDValue x_Root, x_sPath, x_sKey, x_sValue
End Select

RegWrite = Err
Else
RegWrite = “~err”
End If
End Function

‘______________________________________________________________________________________
‘ SKRIV LOGGFIL / Tobias Holm 2010-06-21

‘ Ex: lRet = Logg(“C:\Logs”, “\Fil.LOG”, “Inga fel”)
‘ Returnerar ev felkod under körning.
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function Logg(x_sPath, x_sFile, x_sText)
Set x_oFSO = CreateObject(“Scripting.FileSystemObject”)

‘ Check that the strDirectory folder exists
If x_oFSO.FolderExists(x_sPath) Then
Set x_oFolder = x_oFSO.GetFolder(x_sPath)
Else
Set x_oFolder = x_oFSO.CreateFolder(x_sPath)
End If

If x_oFSO.FileExists(x_sPath & x_sFile) Then
Set x_oFolder = x_oFSO.GetFolder(x_sPath)
Else
Set x_oFile = x_oFSO.CreateTextFile(x_sPath & x_sFile)
End If
Set x_oFile = Nothing
Set x_oFolder = Nothing

‘ForAppending = 8, ForReading = 1, ForWriting = 2
Set objTextFile = x_oFSO.OpenTextFile(x_sPath & x_sFile, 8, True)

‘ Writes strText every time you run this VBScript
objTextFile.WriteLine(Date() & ” ” & Time() & ” ” & x_sText)
objTextFile.Close

Logg = Err.Number
Set x_oFSO = Nothing
End Function

‘______________________________________________________________________________________
‘ LÄS INI / http://www.robvanderwoude.com/vbstech_files_ini.php
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Function ReadIni( myFilePath, mySection, myKey )
‘ This function returns a value read from an INI file

‘ Arguments:
‘ myFilePath  [string]  the (path and) file name of the INI file
‘ mySection   [string]  the section in the INI file to be searched
‘ myKey       [string]  the key whose value is to be returned

‘ Returns:
‘ the [string] value for the specified key in the specified section

‘ CAVEAT:     Will return a space if key exists but value is blank

‘ Written by Keith Lacelle
‘ Modified by Denis St-Pierre and Rob van der Woude

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

Dim intEqualPos
Dim objFSO, objIniFile
Dim strFilePath, strKey, strLeftString, strLine, strSection

Set objFSO = CreateObject( “Scripting.FileSystemObject” )

ReadIni     = “”
strFilePath = Trim( myFilePath )
strSection  = Trim( mySection )
strKey      = Trim( myKey )

If objFSO.FileExists( strFilePath ) Then
Set objIniFile = objFSO.OpenTextFile( strFilePath, ForReading, False )
Do While objIniFile.AtEndOfStream = False
strLine = Trim( objIniFile.ReadLine )

‘ Check if section is found in the current line
If LCase( strLine ) = “[” & LCase( strSection ) & “]” Then
strLine = Trim( objIniFile.ReadLine )

‘ Parse lines until the next section is reached
Do While Left( strLine, 1 ) <> “[”
‘ Find position of equal sign in the line
intEqualPos = InStr( 1, strLine, “=”, 1 )
If intEqualPos > 0 Then
strLeftString = Trim( Left( strLine, intEqualPos – 1 ) )
‘ Check if item is found in the current line
If LCase( strLeftString ) = LCase( strKey ) Then
ReadIni = Trim( Mid( strLine, intEqualPos + 1 ) )
‘ In case the item exists but value is blank
If ReadIni = “” Then
ReadIni = ” ”
End If
‘ Abort loop when item is found
Exit Do
End If
End If

‘ Abort if the end of the INI file is reached
If objIniFile.AtEndOfStream Then Exit Do

‘ Continue with next line
strLine = Trim( objIniFile.ReadLine )
Loop
Exit Do
End If
Loop
objIniFile.Close
Else
WScript.Echo strFilePath & ” doesn’t exists. Exiting…”
Wscript.Quit 1
End If
End Function

‘______________________________________________________________________________________
‘ SKRIV INI / http://www.robvanderwoude.com/vbstech_files_ini.php
‘¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Sub WriteIni( myFilePath, mySection, myKey, myValue )
‘ This subroutine writes a value to an INI file

‘ Arguments:
‘ myFilePath  [string]  the (path and) file name of the INI file
‘ mySection   [string]  the section in the INI file to be searched
‘ myKey       [string]  the key whose value is to be written
‘ myValue     [string]  the value to be written (myKey will be
‘                       deleted if myValue is <DELETE_THIS_VALUE>)

‘ Returns:
‘ N/A

‘ CAVEAT:     WriteIni function needs ReadIni function to run

‘ Written by Keith Lacelle
‘ Modified by Denis St-Pierre, Johan Pol and Rob van der Woude

Const ForReading   = 1
Const ForWriting   = 2
Const ForAppending = 8

Dim blnInSection, blnKeyExists, blnSectionExists, blnWritten
Dim intEqualPos
Dim objFSO, objNewIni, objOrgIni, wshShell
Dim strFilePath, strFolderPath, strKey, strLeftString
Dim strLine, strSection, strTempDir, strTempFile, strValue

strFilePath = Trim( myFilePath )
strSection  = Trim( mySection )
strKey      = Trim( myKey )
strValue    = Trim( myValue )

Set objFSO   = CreateObject( “Scripting.FileSystemObject” )
Set wshShell = CreateObject( “WScript.Shell” )

strTempDir  = wshShell.ExpandEnvironmentStrings( “%TEMP%” )
strTempFile = objFSO.BuildPath( strTempDir, objFSO.GetTempName )

Set objOrgIni = objFSO.OpenTextFile( strFilePath, ForReading, True )
Set objNewIni = objFSO.CreateTextFile( strTempFile, False, False )

blnInSection     = False
blnSectionExists = False
‘ Check if the specified key already exists
blnKeyExists     = ( ReadIni( strFilePath, strSection, strKey ) <> “” )
blnWritten       = False

‘ Check if path to INI file exists, quit if not
strFolderPath = Mid( strFilePath, 1, InStrRev( strFilePath, “\” ) )
If Not objFSO.FolderExists ( strFolderPath ) Then
WScript.Echo “Error: WriteIni failed, folder path (” _
& strFolderPath & “) to ini file ” _
& strFilePath & ” not found!”
Set objOrgIni = Nothing
Set objNewIni = Nothing
Set objFSO    = Nothing
WScript.Quit 1
End If

While objOrgIni.AtEndOfStream = False
strLine = Trim( objOrgIni.ReadLine )
If blnWritten = False Then
If LCase( strLine ) = “[” & LCase( strSection ) & “]” Then
blnSectionExists = True
blnInSection = True
ElseIf InStr( strLine, “[” ) = 1 Then
blnInSection = False
End If
End If

If blnInSection Then
If blnKeyExists Then
intEqualPos = InStr( 1, strLine, “=”, vbTextCompare )
If intEqualPos > 0 Then
strLeftString = Trim( Left( strLine, intEqualPos – 1 ) )
If LCase( strLeftString ) = LCase( strKey ) Then
‘ Only write the key if the value isn’t empty
‘ Modification by Johan Pol
If strValue <> “<DELETE_THIS_VALUE>” Then
objNewIni.WriteLine strKey & “=” & strValue
End If
blnWritten   = True
blnInSection = False
End If
End If
If Not blnWritten Then
objNewIni.WriteLine strLine
End If
Else
objNewIni.WriteLine strLine
‘ Only write the key if the value isn’t empty
‘ Modification by Johan Pol
If strValue <> “<DELETE_THIS_VALUE>” Then
objNewIni.WriteLine strKey & “=” & strValue
End If
blnWritten   = True
blnInSection = False
End If
Else
objNewIni.WriteLine strLine
End If
Wend

If blnSectionExists = False Then ‘ section doesn’t exist
objNewIni.WriteLine
objNewIni.WriteLine “[” & strSection & “]”
‘ Only write the key if the value isn’t empty
‘ Modification by Johan Pol
If strValue <> “<DELETE_THIS_VALUE>” Then
objNewIni.WriteLine strKey & “=” & strValue
End If
End If

objOrgIni.Close
objNewIni.Close

‘ Delete old INI file
objFSO.DeleteFile strFilePath, True
‘ Rename new INI file
objFSO.MoveFile strTempFile, strFilePath

Set objOrgIni = Nothing
Set objNewIni = Nothing
Set objFSO    = Nothing
Set wshShell  = Nothing
End Sub

Categories: Windows Tags:

Commercial programs replacements

August 13th, 2010 No comments

Here’s a list of common commercial programs and their equalizes in the open world:

  • Adobe Lightroom 3 (~ 2300 SEK) – No good replacement exists
  • Adobe Photoshop – GIMP
  • Adobe Acrobat – Use the following programs:
  • Foxit Reader (like Acrobat Reader)
  • PDF Rider (GUI for Pdftk – merge, insert, delete, rotate, extract pages)
  • PDF Toolkit (used by PDF Rider)
  • Manual for Pdftk
  • Microsoft Outlook 2010 (~ 1300 SEK) – Thunderbird
  • Microsoft Word 2010 (~ 1400 SEK) – LibreOffice
  • Microsoft Excel 2010 (~ 1500 SEK) – LibreOffice
  • Microsoft Powerpoint 2010 (~ 1450 SEK) – LibreOffice
  • Microsoft SharePoint – Drupal
  • Microsoft SharePoint – Alfresco Labs 3
  • Microsoft SharePoint – O3Spaces Community Edition
  • Microsoft SharePoint – Umbraco
  • Microsoft SharePoint – Joomla
  • Microsoft SharePoint – OpenCMS
  • Microsoft SharePoint – Typo3
  • Microsoft SharePoint – eZ publish

Open programs sorted in categories:

  • Office -> LibreOffice (alt Openoffice.org 3)
  • Bokföring -> Gnucash
  • Desktop Publishing -> Scribus
  • E-mail -> Zimbra
  • Web editor -> Kompozer
  • Graphics/Paint -> Gimp
  • Backup -> Amanda
  • HR -> Orangehrm
  • E-postkampanjer -> PHPlist
  • Project management -> Openproj
  • Antivirus -> ClamAV

List of some free AntiVirus CD’s: http://www.techmixer.com/free-bootable-antivirus-rescue-cds-download-list/

Copy a CD/DVD to ISO file in Ubuntu:

sudo umount /dev/cdrom
readom dev=/dev/cdrom f=file.iso

Tip about setting up Ubuntu 10.04 with common programs and codecs:

http://theindexer.wordpress.com/2010/03/21/to-do-list-after-installing-ubuntu-10-04-aka-lucid-lynx/

http://howtoforge.com/the-perfect-desktop-ubuntu-10.04-lucid-lynx

Categories: Linux, Ubuntu Tags:

Cache av apt-get paket

August 4th, 2010 No comments

Om du har många likadana servers kan du snabba upp uppdateringen av systemet. För att sätta upp en central server på nätet som buffrar alla uppdateringar i Ubuntu där sedan klienterna kan hämta dessa utan att behöva gå ut på internet:

http://www.debuntu.org/how-to-set-up-a-repository-cache-with-apt-cacher
http://www.debuntu.org/how-to-set-up-a-repository-cache-with-apt-cacher-p2

Eller så kan du sätta upp en server som i förväg hämtar hem alla uppdateringar till en central server:

http://www.howtoforge.com/local_debian_ubuntu_mirror
http://www.packtpub.com/article/create-local-ubuntu-repository-using-apt-mirror-apt-cacher

Categories: Linux, Ubuntu Tags: