bash | Tag | ohneKontur - der Blog https://www.ohnekontur.de ohne Linien und Kanten und trotzdem gefangen Fri, 28 Nov 2014 09:55:57 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.4 `cat` as a shell builtin https://www.ohnekontur.de/2013/02/17/making-cat-a-shell-builtin/ https://www.ohnekontur.de/2013/02/17/making-cat-a-shell-builtin/#comments Sun, 17 Feb 2013 08:48:32 +0000 http://www.ohnekontur.de/?p=2259 Recently i blogged about how to get a process list if you aren’t able to fork any processes . Also a process list is allways handy, i allways find cat a very usefull tool too. But as you might have … Continue reading

The post `cat` as a shell builtin first appeared on ohneKontur - der Blog.]]>
Recently i blogged about how to get a process list if you aren’t able to fork any processes . Also a process list is allways handy, i allways find cat a very usefull tool too. But as you might have noticed cat is not a shell builtin. So everytime cat is called a new process needs to be forked. In case you can’t fork processes it’s a problem, and even if you can fork them you may save resources by “creating” a shell builtin cat.
So lets do this,
open your .profile for usage with your user only or /etc/profile for global usage (You may also use your .bashrc or .zshrc instead).
Append the following lines to the file:

#pseudo bash builtin cat function
function cat { echo “$(< $1)" }

Siehe Kommentar :)

function cat {
  if [ $# -eq 1 -a "${1:0:1}" != "-" ]
  then
    exec 3< "${1:-/dev/stdin}"
    while read -r -u3 line
    do
      echo -E ''"${line}";
    done
    echo -nE ''"${line}";
    exec 3<&-
    else
     /bin/cat "$@"
fi
}

Voila, if you start a new loginshell the cat should refer to a shell function and not to a binary.
(to test this simply type type cat result should be something like cat is a shell function )

The post `cat` as a shell builtin first appeared on ohneKontur - der Blog.]]>
https://www.ohnekontur.de/2013/02/17/making-cat-a-shell-builtin/feed/ 2
How to get a process list if you can’t fork any processes? https://www.ohnekontur.de/2013/01/05/how-to-get-a-process-list-if-you-cant-fork-any-processes/ https://www.ohnekontur.de/2013/01/05/how-to-get-a-process-list-if-you-cant-fork-any-processes/#respond Sat, 05 Jan 2013 09:29:19 +0000 http://www.ohnekontur.de/?p=2214 Recently I got the question what to do if one got a bash session but can’t fork processes on a Linux system. So here is an attempt to get a processlist just by using bash buildins: OLDPWD=$PWD cd /proc for … Continue reading

The post How to get a process list if you can’t fork any processes? first appeared on ohneKontur - der Blog.]]>
Recently I got the question what to do if one got a bash session but can’t fork processes on a Linux system.
So here is an attempt to get a processlist just by using bash buildins:

OLDPWD=$PWD
cd /proc
for x in [0-9]*
do
read cmd < /proc/${x}/comm
read cmdl < /proc/${x}/cmdline
printf "%8s - %15s - %s" $x $cmd $cmdl
echo
done
cd $OLDPWD
The post How to get a process list if you can’t fork any processes? first appeared on ohneKontur - der Blog.]]>
https://www.ohnekontur.de/2013/01/05/how-to-get-a-process-list-if-you-cant-fork-any-processes/feed/ 0
Swapfile – Swap ohne eigenes Dateisystem https://www.ohnekontur.de/2009/11/29/swapfile-swap-ohne-eigenes-dateisystem/ https://www.ohnekontur.de/2009/11/29/swapfile-swap-ohne-eigenes-dateisystem/#respond Sun, 29 Nov 2009 15:10:43 +0000 http://www.ohnekontur.de/?p=636 Ich dachte bis vor kurzen um unter Linux zu Swap-en bräuche man eine Swap Partition. Es zeigte sich, dass das nur halb richtig ist : Den man kann auch eine Datei, die sich in einem normalen Dateisystem befindet (ext3) als … Continue reading

The post Swapfile – Swap ohne eigenes Dateisystem first appeared on ohneKontur - der Blog.]]>
Ich dachte bis vor kurzen um unter Linux zu Swap-en bräuche man eine Swap Partition.

Es zeigte sich, dass das nur halb richtig ist : Den man kann auch eine Datei, die sich in einem normalen Dateisystem befindet (ext3) als Swap Partition Mounten.

Warscheinlich ist das nicht die beste, schönste oder schnellste Methode,
aber mir spaart es das sehr mühevolle ändern meiner Partitionen.

Als machen wirs kurz:

dd if=/dev/zero of=/Datei/in/die/geswapt/werden/soll.swp bs=1M count=512
#count gibt die Größe in MB an und kann nach belieben geändert werden
mkswap /Datei/in/die/geswapt/werden/soll.swp
swapon /Datei/in/die/geswapt/werden/soll.swp
echo >>/etc/fstab "#add new swapfiles"
echo >>/etc/fstab "/Datei/in/die/geswapt/werden/soll.swp swap swap noauto 0 0"
swapon -a
The post Swapfile – Swap ohne eigenes Dateisystem first appeared on ohneKontur - der Blog.]]>
https://www.ohnekontur.de/2009/11/29/swapfile-swap-ohne-eigenes-dateisystem/feed/ 0
Was man besser nicht tun sollte https://www.ohnekontur.de/2009/10/27/was-man-besser-nicht-tun-sollt/ https://www.ohnekontur.de/2009/10/27/was-man-besser-nicht-tun-sollt/#respond Tue, 27 Oct 2009 22:33:47 +0000 http://www.ohnekontur.de/?p=601 Okay zugegeben die meisten werden es wissen, aber trotzdem, als Hinweis für alle dies nicht wissen: macht das nicht: rm -r /etc/* durch ein doofes Missgeschick ist mir das passiert und es ist kein Spaß. Damit wären wir beim zweiten … Continue reading

The post Was man besser nicht tun sollte first appeared on ohneKontur - der Blog.]]>
Okay zugegeben die meisten werden es wissen,
aber trotzdem, als Hinweis für alle dies nicht wissen:

macht das nicht:

rm -r /etc/*

durch ein doofes Missgeschick ist mir das passiert und es ist kein Spaß.

Damit wären wir beim zweiten Punkt:

Sorgt dafür das im Backup die Dateirechte erhalten werden.

So genug der Altklugheit, aber ich musstes mal loswerden.
Ja ich weiß den kram erzählt jeder und ich glaube jeder muss selbst die Erfahrung machen das man die dinge einhalten sollte ;)

The post Was man besser nicht tun sollte first appeared on ohneKontur - der Blog.]]>
https://www.ohnekontur.de/2009/10/27/was-man-besser-nicht-tun-sollt/feed/ 0