preload
Nov 30
Some useful linux find-commands:
Find files with file size between 10 and 20 MB
1
find -size +10M -size -20M
Find files not belonging to user root
1
find ! -user root
Find files greater than 10 MB and list them with ls-lh.
1
find -size +10M -exec ls -lh {} \;
Find files with .jpg ending not case sensitive and create a tar-ball.
1
find -iname '*.jpg' -exec tar -rf bilder.tar {} \;
Find files with .mp3 ending not case sensitive and create a playlist.m3u file
1
find -iname '*.mp3' -fprint playlist.m3u

Find files with SUID bit set.

1
find / -type f -perm +6000 -exec ls -l {}  \; > suid.list

Nov 30

This is an example from http://www.linux-user.de/ausgabe/2001/07/030-split/split.html:

1
tar cz /home/user  | split -b95m - archiv.tgz.split.

Put together files with:

1
cat  [dateiname].split.* | tar x
Tagged with:
Nov 27
I am glad that I could gain experience in a lot of CMS-Systems, Open Source CMS like Typo3 and Joomla as well as Licence CMS for example InterRed. Now I will come to my favorite Open-Source CMS, Typo3!
What if you like to create a “previous” – “next” navigation with typo3? Have a look at the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
lib.nav-referenzen = COA
lib.nav-referenzen {
  10 = HMENU
  10 {
   entryLevel = 3
   special = browse
   special  {
    items = prev
    items.prevnextToSection =  1
   }
   1 = TMENU
   1 {
    NO  {
    doNotLinkIt = 1
    stdWrap.cObject =  COA
    stdWrap.cObject {
     10 =  TEXT
     10 {
      field =  title
      typolink {
       parameter.field = uid
       returnLast =  url
      }
    wrap = <a title="{field:title}" href="|"></a>&amp;nbsp;&amp;nbsp;
    insertData =  1
    }
  }
 }
}
}
20 &lt; .10
20 {
special.items =  next
1.NO.stdWrap.cObject.10.wrap = &amp;nbsp;&amp;nbsp;<a title="{field:title}" href="|">next &amp;raquo;</a>
}
}
Now put this code into your template:

with automaketemplate e.g: subparts.bottom < lib.nav-referenzen

with templavoila e.g.: lib.prevnextnavigation < lib.nav-referenzen

subparts.bottom and lib.prevnextnavigation are only sample object names. Replace them with your own subpartname or templavoila lib name.

Tagged with:
Nov 26

It is not possible in Outlook to send an email blind carbon copy to a special email address automatically. E.g. you would like to send a copy of each email you send to watcher@mymail.com automatically.

A small Visual Basic Script can do the job. Open Outlook 2007 and press Alt+F11 for the Visual Basic Editor and put there the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
 
Dim objItem As MailItem
Dim myRecipients As Recipients
Dim myRecipient As Recipient
 
If Not ActiveInspector Is Nothing Then
If TypeOf ActiveInspector.CurrentItem Is MailItem Then
 
strBcc = "watcher@myemail.com"
End If
End If
 
On Error Resume Next
Set objRecip = Item.Recipients.Add(strBcc)
' handle case of user canceling Outlook security dialog
If Err = 287 Then
strMsg = "Could not add a Bcc recipient " &amp; _
"because the user said No to the security prompt." &amp; _
" Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Security Prompt Cancelled")
If res = vbNo Then
Cancel = True
Else
objRecip.Delete
End If
Err.Clear
Else
objRecip.Type = olBCC
objRecip.Resolve
 
End If
 
Set objRecip = Nothing
 
End Sub

Here is another version where you can filter the recipients and send mails to a special email address. E.g. you would like to send a bcc automatically to company1@mymail.com if you send mails to *@company1.com and to company2@mymail.com if you send mails to *@company2.com:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer
Dim strBcc As String
 
Dim objItem As MailItem
Dim myRecipients As Recipients
Dim myRecipient As Recipient
 
If Not ActiveInspector Is Nothing Then
If TypeOf ActiveInspector.CurrentItem Is MailItem Then
Set objItem = ActiveInspector.CurrentItem
Set myRecipients = objItem.Recipients
myRecipients.ResolveAll
For Each myRecipient In myRecipients
 
strBcc = ""
 
If InStr(myRecipient.Address, "company1.com") Then
strBcc = "company1@mymail.com"
End If
If InStr(myRecipient.Address, "company2.com") Then
strBcc = "company2@mymail.com"
End If
 
Next
End If
End If
 
On Error Resume Next
Set objRecip = Item.Recipients.Add(strBcc)
' handle case of user canceling Outlook security dialog
If Err = 287 Then
strMsg = "Could not add a Bcc recipient " &amp; _
"because the user said No to the security prompt." &amp; _
" Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Security Prompt Cancelled")
If res = vbNo Then
Cancel = True
Else
objRecip.Delete
End If
Err.Clear
Else
objRecip.Type = olBCC
objRecip.Resolve
 
End If
 
Set objRecip = Nothing
 
End Sub
Tagged with:
Nov 25

To replace a string in all files inside a folder you can create a bash file:

1
vi replace.sh

Put inside this file:

1
2
3
4
5
6
#!/bin/bash
for file in $(ls -1);
do
sed 's/me/you/g' $file &gt; /tmp/dummy.txt;
mv /tmp/dummy.txt $file;
done

Save it and make it executeable (chmod 777 replace.sh)

In this case the string “me” will be replace with “you” in all files of the actual folder and the files will be overridden.
Another example
Your want to replace the tag <b> with <strong> in all files inside a special folder. Further you want to backup the original files with suffix .old and the new files will be overridden.
Simply type on the console:
1
2
3
4
5
for file in $(ls -1);
do
mv $file $file.old
sed 's/&lt;b&gt;/&lt;strong&gt;/g' $file.old &gt;  $file;
done
You can modify the script(s). Maybe by adding parameters etc.

Another option is to use sed with -i command or direct editing:

1
2
3
4
for file in $(ls -1);
do
sed -i 's/text_to_replace/text_replacement/g' $file
done
Tagged with:
Nov 25

People often underestimate the usefulness of the linux-command screen.

What does screen do? Screen creates a terminal session for the actual user.

Type:

1
screen

to create a terminal session.

Or type:

1
screen -S <sessionname>

where <sessionname> should be replaced with your own name.

Create a new window:

1
Crtl+a c

which means (Press Control and a together and after that press c)

Now we created a second window. To list all created windows in the actual session type:

1
Crtl+a "

Germans have to press Shift+2 for “.

Now the two created windows will be shown:

Bildschirmfoto 2009-11-25 um 14.55.07

Just choose one Window and press enter.

To quit your actual work an detach the session:

1
Crtl+a d

To list all active sessions:

1
screen -list

You should see a similar picture like the following:

Bildschirmfoto 2009-11-25 um 15.03.27

Here you can see the name of the session: 1597.stefan

To restore the session simply type:

1
screen -r stefan

Maybe you have to type the complete id with 1597.stefan if there exist another session with the same name.

Tagged with:
Nov 19

When switching from Mac to Linux and vice versa, I always have to think a bit about how to use the command top and sort by CPU.

With Linux it is

top

and then press

shift+p

Mac:

top -o cpu

I hope I can remember this :-)

Tagged with:
Nov 18

The situation is as follows. You want to search recursive for a text pattern inside of each files in the directory /var/www/vhosts. Take e.g. the pattern ‘DataStructure’.

Normally you would think about the find-command and executing another command but grep itself can do the job.

grep -RHl -e ‘DataStructure’ /srv/www/vhosts

This command lists all filenames containing the text ‘DataStructure’

Tagged with:
Nov 16

To list all open connections on the actual linux or mac just type the following:

lsof -i

For faster lookup without replacing IP through DNS-lookup:

lsof -i -n

Try also with root-permission for more files:

sudo lsof -i -n

Now you can easily spot programs connecting to the internet an dump the tcp-data with tcpdump.

For example dumping data from tcp-port 80 to a file called test.pcap:

tcpdump -w test.pcap tcp port 80

Now show the file:

tcpdump -nnr test.pcap

or

tcpdump -ttttnnr test.pcap

for timestamp information

Tagged with:
Nov 16

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();

Tagged with: