So today I needed to replace a few hundred href link in varying content today. Here's my take on solving it. This works in zsh. I think for bash you need to add the do and done parts of the for loop, i'm not sure.
for file in `grep -lR "href=\"\/static\/" .`; sudo sed -i -e 's/href=\"\/static\//href=\"\/applications\/static\//g' $file
Wednesday, 23 January 2013
Thursday, 17 January 2013
SSH Pseudo terminals
There is always so much more to SSH than I know about. Here is another discovery I made today. This allows me to ssh into a machine via a gateway in just one command care of the -t flag
ssh -t agatewaymachine.com "ssh 192.168.1.253"
ssh -t agatewaymachine.com "ssh 192.168.1.253"
Wednesday, 16 January 2013
Disable php deprecation warnings per apache virtual host
php_value error_reporting 6135
Seems you have to use the numerical value in apache for this. This should be all E_ALL minus E_DEPRECATED AND E_USER_DEPRECATED
This will only work if the error handling function is not overridden in the php code.
This will only work if the error handling function is not overridden in the php code.
Thursday, 15 November 2012
Life with systemd Part 2
systemd rocks! I really did not think I had the patience to learn it, but now I understand it and have played about with it, I think it is brilliant if not for one reason alone - creating service files are trivial, which is how it should be. In SysVInit I rarely bothered.
Here's one I knocked up for icecast. There was already a rc script for it running under under systemd but I decided to create my own systemd service file as a test. To install was was simply a matter of:-
systemctl stop icecast.service
systemctl disable icecast.service
cp icecast.service /lib/systemd/system/icecast.service,
and then activating it again with systemctl enable icecast.service
systemd realised it had a service file for it and uses that rather that the installed /etc/rc.d/icecast file which I could leave installed. I'm impressed.
Here's the icecast.service file I created. I had to uncomment the pid file option in icecast.xml. I also changed the path to /var/run
[Unit]
Description=Icecast 2.x Server
[Service]
ExecStart=/usr/bin/icecast -b -c /etc/icecast.xml
Type=forking
PIDFile=/var/run/icecast.pid
[Install]
WantedBy=multi-user.target
Here's one I knocked up for icecast. There was already a rc script for it running under under systemd but I decided to create my own systemd service file as a test. To install was was simply a matter of:-
systemctl stop icecast.service
systemctl disable icecast.service
cp icecast.service /lib/systemd/system/icecast.service,
and then activating it again with systemctl enable icecast.service
systemd realised it had a service file for it and uses that rather that the installed /etc/rc.d/icecast file which I could leave installed. I'm impressed.
Here's the icecast.service file I created. I had to uncomment the pid file option in icecast.xml. I also changed the path to /var/run
[Unit]
Description=Icecast 2.x Server
[Service]
ExecStart=/usr/bin/icecast -b -c /etc/icecast.xml
Type=forking
PIDFile=/var/run/icecast.pid
[Install]
WantedBy=multi-user.target
Life With systemd Part1
I rolled out a new server recently and very nearly did not put opensuse on it based and the thought of having to learn systemd. I can see why SysVInit could have done with being replaced but I didn't really see it as pressing. Anyway, here's my braindump of learning it so far!
First thing I dislike is that it pages to $PAGER by default. Let's turn that off
export SYSTEMD_PAGER='' (I've added this to my ~/.zshrc)
ls -l /etc/systemd/system/default.target - What is the default target? (usually a symlink to another target)
systemctl show -p Wants default.target - What does this target load (want and can fail)
systemctl show -p Requires default.target - What does this target load (want and can't fail)
systemctl show -p MainPID icecast.service - Show the main pid of the process (0 if not running)
systemctl show -p icecast.service - Show all systemd values for icecast.service
systemctl {start,stop,restart} something.service - Like service something {start,stop.restart}
systemd-analyze blame - How long did each unit take to start
systemctl list-unit-files - list all available systemd unit files
systemctl list-unit - list all loaded units
filter the above 2 outputs e.g.
systemctl list-units --type=service or
systemctl --type=service - show running services
systemctl --type=target - show running targets
First thing I dislike is that it pages to $PAGER by default. Let's turn that off
export SYSTEMD_PAGER='' (I've added this to my ~/.zshrc)
ls -l /etc/systemd/system/default.target - What is the default target? (usually a symlink to another target)
systemctl show -p Wants default.target - What does this target load (want and can fail)
systemctl show -p Requires default.target - What does this target load (want and can't fail)
systemctl show -p MainPID icecast.service - Show the main pid of the process (0 if not running)
systemctl show -p icecast.service - Show all systemd values for icecast.service
systemctl {start,stop,restart} something.service - Like service something {start,stop.restart}
systemd-analyze blame - How long did each unit take to start
systemctl list-unit-files - list all available systemd unit files
systemctl list-unit - list all loaded units
filter the above 2 outputs e.g.
systemctl list-units --type=service or
systemctl --type=service - show running services
systemctl --type=target - show running targets
Wednesday, 14 November 2012
Fun with lsof
lsof (list open files) is a tool I have used recently for discovering which service is using a certain port. We also had a issue recently where our /var partition was showing 0 bytes free, but du -csh /var was showing over 1.5GB free. Using lsof | grep deleted we were able to determine that processes were still holding files open that had since been (erroneously) deleted. Here are some more examples of lsof that I like.
sudo lsof -i4 -sTCP:LISTEN -P - As above but don't lookup service names
sudo lsof -i:22 - List all open internet sockets using port 22 (who is using port 22)
sudo lsof -i4 -sTCP:LISTEN - List all IPv4 internet sockets (-i4) in state Listen (-sTCP:LISTEN) This is should list all listening services (not working on centos 5)
sudo lsof -i4 -sTCP:LISTEN -P - As above but don't lookup service names
sudo lsof -u icecast - List all open files used by user icecast (-u icecast)
sudo lsof -u icecast -a -i List all open files used by user icecast and (-a) only internet sockets (-i)
sudo lsof -p 3893 - List all open files of pid 3893
sudo lsof -P -c ushare -a -i - List open files for processes executing a command beginning with "ushare" (-c) and (-a) internet sockets. Don't lookup the service in /etc/services(-P)
sudo lsof -P -c ushare -a -i -sTCP:LISTEN As above but only the the listening ports for TCP
sudo lsof -i4 -sTCP:LISTEN -a -p 3792 -P - Show listening IP4 TCP ports for process 3792
sudo lsof -P -c ushare -a -i - List open files for processes executing a command beginning with "ushare" (-c) and (-a) internet sockets. Don't lookup the service in /etc/services(-P)
sudo lsof -P -c ushare -a -i -sTCP:LISTEN As above but only the the listening ports for TCP
sudo lsof -i4 -sTCP:LISTEN -a -p 3792 -P - Show listening IP4 TCP ports for process 3792
Wednesday, 20 June 2012
Vim formatting goodness
So I wanted to paste this licence into my piece of code http://www.opensource.org/licenses/bsd-license.php
But I wanted it be wrapped to no more than 79 characters a line and before each sentence I wanted to insert a "# "
This is how
:set paste (paste text from web browser)
highlight area with shift V
! fmt -77 (keep 2 characters for "# ")
s!^!# !
Love it!
But I wanted it be wrapped to no more than 79 characters a line and before each sentence I wanted to insert a "# "
This is how
:set paste (paste text from web browser)
highlight area with shift V
! fmt -77 (keep 2 characters for "# ")
s!^!# !
Love it!
Subscribe to:
Posts (Atom)