LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Blogs > sag47
User Name
Password

Notices


  1. Old Comment

    Cloning a git repository in an idempotent way

    This blog post is useless due to the advent of the smart git protocol. Since sites using the "dumb protocol" are becomming rare this post has limited, if any, use.
    Posted 12-07-2015 at 01:48 PM by sag47 sag47 is offline
  2. Old Comment

    Cloning a git repository in an idempotent way

    I was thinking of attempting parsing the default branch with the following.

    Code:
    git ls-remote origin | awk '$2 == "HEAD" { head=$1; next}; $1 == head && $2 ~ /^refs\/heads/ {sub(/refs\/heads\//, "",$2);print $2}'
    However, if more than one branch refers to the same reference then that breaks. It's hard to determine the default branch.
    Posted 05-20-2015 at 02:19 AM by sag47 sag47 is offline
  3. Old Comment

    Batch convert images to PDF

    My examples listed above are a pile of crap. Here's a better way of doing the above.

    For JPG images,
    Code:
    for x in *.jpg;do convert "${x}" "${x%.jpg}.pdf";done
    The above example is better because it takes advantage of name globbing in bash for the *.jpg and when renaming the image to a PDF file it removes the .jpg extension first using bash parameter expansion.
    Posted 08-03-2013 at 09:50 AM by sag47 sag47 is offline
  4. Old Comment

    SELinux and Icinga

    Recently I compiled icinga-web. It requires the following security contexts to be appended to /etc/selinux/targeted/contexts/files/file_contexts.local
    Code:
    /usr/local/icinga-web/app(/.*)?  system_u:object_r:httpd_sys_content_t:s0
    /usr/local/icinga-web/lib(/.*)?  system_u:object_r:httpd_sys_content_t:s0
    /usr/local/icinga-web/pub(/.*)?  system_u:object_r:httpd_sys_content_t:s0
    /usr/local/icinga-web/app/cache(/.*)? system_u:object_r:httpd_sys_rw_content_t:s0
    /usr/local/icinga-web/log(/.*)? system_u:object_r:httpd_sys_rw_content_t:s0
    Now restore the contexts.
    Code:
    restorecon -R /usr/local/icinga-web
    Posted 04-16-2013 at 11:00 PM by sag47 sag47 is offline
  5. Old Comment

    SELinux and Icinga

    I forgot to mention but in my previous comment once I created the security contexts for Icinga I used the restorecon command on those three folders so that they work with SELinux.

    Code:
    restorecon -R /usr/local/icinga/sbin
    restorecon -R /usr/local/icinga/share
    restorecon -R /usr/local/icinga/var
    Posted 01-13-2013 at 10:57 PM by sag47 sag47 is offline
  6. Old Comment

    Using a script to get your IP address

    Thanks . I was discussing it with my local LUG mailing list and here's a good solution they came up with which will present the IP address of the default route (I substituted some of their cuts with awk instead).

    Code:
    ip -o ro get $(ip ro | awk '$1 == "default" { print $3 }') | awk '{print $5}'
    The main reason why I used
    Code:
    sed -ne '/^eth2/,/^\s\+Interrupt/p'
    is because I wanted to assume there may be more than one network interface. The sed command helps with cutting out the information only for the intended interface, eth2. It was a fun discussion.
    Posted 01-08-2013 at 04:35 PM by sag47 sag47 is offline
  7. Old Comment

    Using a script to get your IP address

    Save two commands, get more awk for free:
    Code:
    /sbin/ifconfig | awk '/inet addr:/ {if ($2 !~ "127.*") print substr($2,6)}'
    Posted 01-07-2013 at 06:32 PM by unSpawn unSpawn is offline
  8. Old Comment

    SELinux and Icinga

    Here's the now recommended way of managing file_contexts.local using the semanage utility.

    Code:
    semanage fcontext -a -t httpd_sys_script_exec_t '/usr/local/icinga/sbin(/.*)?'
    semanage fcontext -a -t httpd_sys_content_t '/usr/local/icinga/share(/.*)?'
    semanage fcontext -a -t httpd_sys_rw_content_t '/usr/local/icinga/var(/.*)?'
    Warning: The rest of the comment is the old method of manually editing file_contexts.local. I left it for documentation purposes however you should execute the semanage commands I outlined above.


    I added the following lines to /etc/selinux/targeted/contexts/files/file_contexts.local
    Code:
    /usr/local/icinga/sbin(/.*)?  system_u:object_r:httpd_sys_script_exec_t:s0
    /usr/local/icinga/share(/.*)? system_u:object_r:httpd_sys_content_t:s0
    /usr/local/icinga/var(/.*)? system_u:object_r:httpd_sys_rw_content_t:s0
    After that submitting cmd.cgi (reschedule command checks) worked again.
    Posted 08-23-2012 at 11:13 PM by sag47 sag47 is offline
    Updated 06-18-2013 at 09:14 AM by sag47
  9. Old Comment

    SELinux, syslog-ng, and the like

    Note, setroubleshoot-server continued to be noisy on my server. After some research I found that setroubleshoot-server sends email alerts on AVC denies and other SELinux warnings. However, for a server it's not necessary to have installed.

    I removed it to cut down on log noise because I don't care if something gets denied. Let me rephrase that, I don't need to be emailed every time SELinux denies something because I won't change the security to allow certain things.

    Removed packages include:
    • setroubleshoot-server
    • setroubleshoot (depends on setroubleshoot-server)
    • setroubleshoot-plugins (depends on setroubleshoot-server)
    Posted 06-19-2012 at 10:23 AM by sag47 sag47 is offline
    Updated 06-19-2012 at 10:25 AM by sag47
  10. Old Comment

    Monitoring sound over time for long periods to see trends using a microphone

    Thanks unSpawn for an emailed patch which creates more secure temporary files. Here's his code after applying the patch.

    Code:
    #!/bin/sh
    
    case $1 in
       config)
               cat <<EOM
    graph_title Sound Amplitude
    graph_args -l -1 --upper-limit 1
    graph_vlabel Amplitude
    graph_info Shows the sound amplitude values during the 1 second interval recorded discretely every minute.
    mxamp.label max_ampl
    mxamp.info Maximum amplitude
    mnamp.label min_ampl
    mnamp.info Minimum amplitude
    mdamp.label mid_ampl
    mdamp.info Midline amplitude
    EOM
               exit 0;; 
    esac
    
    LANG=C; LC_ALL=C; export LANG LC_ALL; MYTMPDIR=`mktemp -p /tmp -d ampl.XXXXXXXXXX` && {
      arecord -d 1 -f cd -t wav "${MYTMPDIR}/foo.wav" &> /dev/null
      echo -n "mxamp.value " 
      sox "${MYTMPDIR}/foo.wav" -n stat 2>&1 | awk '/Maximum amplitude/ {print $3}'
      echo -n "mnamp.value "
      sox "${MYTMPDIR}/foo.wav" -n stat 2>&1 | awk '/Minimum amplitude/ {print $3}'
      echo -n "mdamp.value "
      sox "${MYTMPDIR}/foo.wav" -n stat 2>&1 | awk '/Midline amplitude/ {print $3}'
      rm -rf "${MYTMPDIR}"
    }
    
    exit 0

    SAM
    Posted 06-12-2012 at 09:52 AM by sag47 sag47 is offline
    Updated 06-12-2012 at 11:09 AM by sag47
  11. Old Comment

    DVD Ripping

    I found a nice solution for lossless encoding using ffmpeg. I think I like it more than use mencoder.

    Code:
    ffmpeg -i VTS_01_1.VOB -acodec libfaac -aq 100 -ac 2 -ab 128k -vcodec libx264 -vpre lossless_medium -threads 4 video.mp4
    From the man page I used the FAAC audio codec with audio quality 100% (-aq 100), two audio channels (-ac 2), and an audio bitrate of 128kbps (-ab 128k).

    For the video quality I used some preinstalled presets.
    Quote:
    Originally Posted by ffmpeg man page
    Code:
           If no such file is found, then ffmpeg will search for a file named
           codec_name-arg.ffpreset in the above-mentioned directories, where
           codec_name is the name of the codec to which the preset file options
           will be applied. For example, if you select the video codec with
           "-vcodec libx264" and use "-vpre max", then it will search for the file
           libx264-max.ffpreset.
    The quality preset file can be found at (on my system):
    /usr/share/ffmpeg/libx264-lossless_medium.ffpreset

    The -threads means that it will encode the video taking advantage of multiple cores on a system. I have four processing cores so I set threads to 4 (-threads 4).

    Sources:
    http://superuser.com/questions/22777...on-with-ffmpeg
    http://ubuntuforums.org/showthread.php?t=1564791

    I got ffmpeg for Fedora 16 from these repositories.
    Code:
    rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
    rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
    You may find that you won't have the required codecs. I had to use an alternate audio codec other than faac because it wasn't available for my system. You can view available codecs for ffmpeg with the following command.

    Code:
    ffmpeg -codecs
    Posted 06-11-2012 at 08:19 PM by sag47 sag47 is offline
    Updated 06-11-2012 at 08:32 PM by sag47
  12. Old Comment

    Convert and resize images using imagemagick

    Just resized pictures 25% smaller and used a better way to change extensions which I outlined in this thread.

    Code:
    for x in *.JPG;do convert -resize 25% $x processed/${x%.JPG}.jpg;done
    ${x%.JPG} takes .JPG off of the end of the variable $x which allows me to rename all the pictures from .JPG to .jpg extension with the following variable "${x%.JPG}.jpg"
    Posted 03-03-2012 at 05:28 PM by sag47 sag47 is offline
    Updated 03-03-2012 at 05:32 PM by sag47
  13. Old Comment

    SELinux and sshd

    I probably should have mentioned this but if you have the
    Code:
    AllowGroups wheel
    setting then only users who belong to the wheel group are able to ssh into the system.

    Here's an example of adding a user who can't ssh and then adding that user to a group so they can ssh.
    Code:
    adduser test
    usermod -a -G wheel test
    Now user test can ssh into the system but other users can't. Mind you those commands are for RHEL/Fedora. If you have a different OS then you should research user management for your system.
    Posted 01-03-2012 at 10:14 PM by sag47 sag47 is offline
    Updated 01-03-2012 at 10:15 PM by sag47
  14. Old Comment

    openbox and repeating keys

    Unfortunately this appears to break when using Synergy. Switching away from the screen and back seems to cause the xset command to disable. By disable I mean you have to run the xset r on command again for it to work again. But switching screens will turn it off every time.
    Posted 12-12-2010 at 01:15 PM by sag47 sag47 is offline

  



All times are GMT -5. The time now is 12:47 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration