Welcome to my website. I am always posting links to photo albums, art, technology and other creations. Everything that you will see on my numerous personal sites is powered by the formVistaTM Website Management Engine.

icon.linkedin.jpgicon.twitter.jpg

  • Subscribe to this RSS Feed
  • Perl One-Liner for Replacing Multiple Lines of a Text file With Multiple Lines of Text
    10/27/2015 2:47PM

    When executing 'search-and-replace' commands on ASCII under Linux, Unix (or *nix) operating systems, sed works or most cases and makes for reasonably straightforward reading of the script.

    If  you want to replace multiple lines of text with multiple lines of text, following is a perl one-liner that does the trick and is much easier to wrangle than trying to do it in sed.

    perl -i -pe "BEGIN{undef $/;} s:${EXISTING_LINES}:${REPLACEMENT_TEXT}:smg" file.txt

  • Adding the Contents of a Source File to the Beginning of a Target File
    10/26/2015 4:49PM

    Following is *nix a command that you can use to add the contents of a source text file to the start of another text file (the source file).

    $ echo -e '0r <source_file_name>\nw' | ed -s <target_file_name>

  • Creating a Samba Share and Configuring an Access Control List for a Shared Directory Under Linux
    10/18/2015 5:08AM

    Often administrators would like to configure a Samba share that enables users to have the same access to any files within the share.  Without some additional configuration, directories and files created by one user will not have the r/w permissions for other users that have access to that same share.

    The end goal is to have a Samba share in which any new files are created with r/w permissions for a specific group to which all of the members of the share belong.

    The first step is to determine whether the current running kernel supports ACL.  To do this we check the configuration file that was used to build the kernel, looking for config keys that contain the string 'POSIX_ACL'.

    Determine the version of your current kernel

    # uname -a
    Linux leviathan 2.6.32-358.2.1.el6.x86_64 #1 SMP Wed Mar 13 00:26:49 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

    Then grep the config file for your kernel

    # grep POSIX_ACL /boot/config-2.6.32-358.2.1.el6.x86_64
    CONFIG_EXT2_FS_POSIX_ACL=y
    CONFIG_EXT3_FS_POSIX_ACL=y
    CONFIG_EXT4_FS_POSIX_ACL=y
    CONFIG_FS_POSIX_ACL=y
    CONFIG_XFS_POSIX_ACL=y
    CONFIG_BTRFS_FS_POSIX_ACL=y
    CONFIG_TMPFS_POSIX_ACL=y
    CONFIG_JFFS2_FS_POSIX_ACL=y

    If the configuration for the filesystem type that you are using on the disk on which you want to configure the share indicates 'y', then you can continue to the next step.  If not, you will need to recompile your kernel with ACL support.

    Next, check the configuration entry in /etc/fstab for the filesystem that we want to use.

    /dev/sda1               /usr/local2/            ext3    defaults        1 2

    In this case, our filesystem is not yet configured to use acl as it is not noted after the 'defaults' option.

    Edit /etc/fstab and change that option to read 'defaults,acl' as follows:

    /dev/sda1               /usr/local2/            ext3    defaults,acl        1 2

    Unmount, and then re-mount the filesystem.

    Next, ensure that you already have a group configured for the users in question and that those users belong to that group.  For this example our group will be 'sharegroup'

    Then, create the directory that you want to share via Samba and set the permissins and acl for it.

    # mkdir /usr/local2/share

    Change the group ownership, permissions, and set the sgid flag.

    # chgrp sharegroup /usr/local2/share

    # chmod g+w share

    # chmod g+x share

    # chmod g+s share

    Now we set the acl for the directory.  The following sets the default group to 'sharegroup' with permissions of 'rwx'.

    # setfacl -m d:g:sharegroup:rwx share/

    The last thing to do is to set up the share in Samba.  Edit /etc/samba/smb.conf

    [share]
            comment =  Shared Directory
            path = /usr/local2/share
            valid users = user1 user2
            browseable = yes
            writeable = yes
            create mask = 2664
            directory mask = 2775

    The key configurations are the create and directory mask which will ensure that files are created with the proper group permissions to enable all of the users the desired access.

    Restart samba and you are finished.

    If you copy an existing directory into the share directory you will need to modify the permissions so that it is available to all of the users who have access to that share.

    Add sgid permissions to all of the sub directories:

    # find ./new_dir -type d -exec chmod g+s {} \;

    Add executable permissions for the group to all of the sub directories:

    # find ./new_dir -type d -exec chmod g+x {} \;

    Add write permissions to all files and directories in the new dir:

    # chmod -R g+w ./new_dir




  • Updating all of the pom.xml Version Numbers in a Multi-Module Maven Project
    10/13/2015 5:05PM

    To update the versions of all of the poms in a multiple module project use the versions-maven plugin.

    To update

    $ mvn versions:set -DnewVersion=1.4.0-SNAPSHOT

    Will modify all of the versions of each of the poms to the version specified.  It will create a pom.xml.versionsBackup for each pom file that it modified.  You can then examine each to make sure that it is as you intended.

    If you want, you can revert your change with

    $ mvn versions:revert

    If you are satisfied with the change, you can commit the change with

    $mvn versions:commit

  • Use awk to Print from nth element to the End of the Line
    09/15/2015 5:03PM

    If you want to extract from the nth token to the end of the line, following is how you can do that with awk:

    Given a source file with the following:

    line1 -- 01   0011 1
    line2 -- 01   0011 2
    line3 -- 01   0011 3
    line4 -- 01   0011 4
    line5 -- 01   0011 5
    line6 -- 01   0011 6
    line7 -- 01   0011 7
    line8 -- 01   0011 8
    line9 -- 01   0011 9
    line10 -- 01   0011 10

    If you want remove the 1st, 2nd, and 3rd items from the list, you can use awk to set those fields to an empty value as follows

    awk '{$1=$2=$3=""; print $0}' test.out

    Which will result in:

       value1 00 0011 1
       value2 00 0011 2
       value3 00 0011 3
       value4 00 0011 4
       value5 00 0011 5
       value6 00 0011 6
       value7 00 0011 7
       value8 00 0011 8
       value9 00 0011 9
       value10 00 0011 10

Advanced Search

Categories

Archives