#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Killing of inactive sesions older than a day


    Appreciate your help for the below.
    I have to kill the Pid`s where Stime greater than previous day.

    File data is like the below:

    DSnum Uid Pid Ppid C Stime Tty Time Command
    53086 dsadm 241812 1667206 0 Sep 27 - 0:00 dsapi_slave 7 6 0
    36690 dsadm 1568848 1958134 0 05:50:29 - 0:00 dsapi_slave 7 6 0
    36544 dsadm 1700058 1544214 0 Sep 26 - 0:01 dsapi_slave 7 6 0
    36612 dsadm 1831054 1933432 0 Sep 26 - 0:00 dsapi_slave 7 6 0
    61134 dsadm 1446106 1441968 0 Sep 26 - 0:01 dsapi_slave 7 6 0
    44932 dsadm 1364010 1466594 0 Sep 26 - 0:00 dsapi_slave 7 6 0
    52914 dsadm 1618156 1097902 0 Sep 23 - 0:00 dsapi_slave 7 6 0
    44870 dsadm 1298540 540682 0 Sep 23 - 0:00 dsapi_slave 7 6 0
    61178 dsadm 1642658 1634464 0 Sep 22 - 0:01 dsapi_slave 7 6 0


    I have tried with sed command like

    sed -n '/Aug/,/Sep/p' file_name,grep "Aug" file_name etc., but couldn`t able to fulfill \
    my requirement.

    Could you please help me on this?
    -Ravi
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    use gawk


    Try one of these untested pipelines:

    Code:
    gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash
    
    ps -your -funny -arguments | gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash

    When I'm doing this sort of thing I usually test first by putting "echo" just before "kill"
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0
    Thanks a lot David Lambert for your response.

    awk function is working in my unix macine but awk function throwing error like 'gawk not found'.

    I have used the below command
    awk '$6~/^[A-Z]/ {print "echo " $3}' temp.txt

    but it is not dispalying first row and output is like the below.
    echo Uid
    echo 1700058
    echo 1831054
    echo 1446106
    echo 1364010
    echo 1618156
    echo 1298540
    echo 1642658

    even though I have sorted date filed but same problem.
    Plesae help me.
    Originally Posted by b49P23TIvg
    Try one of these untested pipelines:

    Code:
    gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash
    
    ps -your -funny -arguments | gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash

    When I'm doing this sort of thing I usually test first by putting "echo" just before "kill"
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    Change the condition.


    Code:
    $ awk '/^[1-9]/&&($6~/^[A-Z]/){print"echo kill -9",$3}' data | bash
    kill -9 241812
    kill -9 1700058
    kill -9 1831054
    kill -9 1446106
    kill -9 1364010
    kill -9 1618156
    kill -9 1298540
    kill -9 1642658
    In this case the {action} happens only when the head of line starts with [1-9] and field 6 contains a first character of [A-Z] . Test against your current processes. When satisfied, remove echo.

    I cannot explain the exclusion of process 241812 based on appearances. You would have to upload your data file. Recreate your data file by cut-n-paste from this forum to fix the trouble you demonstrated.
    Last edited by b49P23TIvg; October 3rd, 2011 at 10:38 AM. Reason: finish business
  8. #5
  9. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    694
    Rep Power
    95

    git: writing files


    Oops. I posted in the wrong place. SORRY!
    I am new to git and I have installed a client on two computers and I am able to manage changes to the git repository from either computer. I see the diffs and I am happy so far. I have a website that we manage the data through git but my question has to do with writing the data from the git repository back to public_html. Can I write the data from the git to public_html using git or do I have to write a bash script myself that will do that?

    Thanks,
    Evan
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    DataStage Job Export from unix


    Its working with the below code now.

    ps -u dsadm | awk '$6~/^[A-Z]/ {print "kill -9 " $3}' ActiveSessions.txt.

    Thanks a lot for your Help David.

    One more help please...

    I would like to take backup(export) of DataStage jobs(not all jobs) which has modified yesterday(incremental backup).

    by using DsExport command we can take back up of particular job or a project.But how can we export by last modified date?

    Appreciate your help on this. Thanks in advance.



    Originally Posted by b49P23TIvg
    Code:
    $ awk '/^[1-9]/&&($6~/^[A-Z]/){print"echo kill -9",$3}' data | bash
    kill -9 241812
    kill -9 1700058
    kill -9 1831054
    kill -9 1446106
    kill -9 1364010
    kill -9 1618156
    kill -9 1298540
    kill -9 1642658
    In this case the {action} happens only when the head of line starts with [1-9] and field 6 contains a first character of [A-Z] . Test against your current processes. When satisfied, remove echo.

    I cannot explain the exclusion of process 241812 based on appearances. You would have to upload your data file. Recreate your data file by cut-n-paste from this forum to fix the trouble you demonstrated.
  12. #7
  13. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    find -mtime


    Read the find man page. It's long. Ask for more help if you get a command that's close. I always have trouble understanding the double negatives and time formats. (The mtime will be argument will be +1, -1, or 1 I'm thinking.) The file name is usually important for my applications, so I include the -name argument. The command will be something like:

    to list the files:

    Code:
    $ find path/to/top/of/interesting/tree -mtime 1 -name 'shell*glob[a-q]pattern.db?' -print
    to use them directly (-print for your pleasure, otherwise useless):
    Code:
    $ find path -mtime 1 -name 'pattern' -print  -exec DsExport -DsExport args {} \;
    Hmm, you might be able to solve your original question with a find /proc command.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0

    Problem with junk characters while rediercting the file


    Greetings David!

    I am having problem while redirecting the file.

    bin/uv -admin -info > SessionInfo.txt

    when giving above command I got data like the below in the file.

    Details for DataStage Engine release 7.5.3.1 instance "ade"
    ===============================================================================
    Install history : Installed by dsadm (admin:dsadm) on: Jul 14 2010 10:55:13
    Instance tag : ade
    Engine status : Running w/active nls
    Engine location : /vol01/home/dsadm/Ascential/DataStage/DSEngine
    Binary location : /vol01/home/dsadm/Ascential/DataStage/DSEngine/bin
    Impersonation : Enabled
    Administrator : dsadm
    Autostart mode : enabled
    Autostart link(s) : /etc/ds.rc
    Startup script : /vol01/home/dsadm/Ascential/DataStage/DSEngine/sample/ds.rc
    Cache Segments : 0 active
    User Segments : 26 active

    19 printer segments abandoned!
    7 phantom printer segments!
    DSnum Uid Pid Ppid C Stime Tty Time Command
    44960 dsadm 1560578 1568816 0 04:42:47 - 0:00 dsapi_slave 7 6 0
    61160 dsadm 1675442 1761442 0 Oct 18 - 0:00 dsapi_slave 7 6 0
    61276 dsadm 1314900 1458312 0 04:41:08 - 0:00 dsapi_slave 7 6 0
    65198 dsadm 1769702 1745026 0 04:32:29 - 0:00 dsapi_slave 7 6 0
    65296 dsadm 1409178 1728522 0 Oct 19 - 0:00 dsapi_slave 7 6 0
    44744 dsadm 1462496 1683488 0 Oct 19 - 0:00 dsapi_slave 7 6 0
    36694 dsadm 913524 1753272 0 07:34:35 - 0:00 dsapi_slave 7 6 0


    But some underline characters displaying (^[[4m) in the file when checking in vi mode which I need to remove with some command(not in vi mode).

    Please check the below file and help me with a command to remove those characters.

    Details for DataStage Engine release 7.5.3.1 instance "ade"
    ===============================================================================
    Install history : Installed by dsadm (admin:dsadm) on: Jul 14 2010 10:55:13
    Instance tag : ade
    Engine status : Running w/active nls
    Engine location : /vol01/home/dsadm/Ascential/DataStage/DSEngine
    Binary location : /vol01/home/dsadm/Ascential/DataStage/DSEngine/bin
    Impersonation : Enabled
    Administrator : dsadm
    Autostart mode : enabled
    Autostart link(s) : /etc/ds.rc
    Startup script : /vol01/home/dsadm/Ascential/DataStage/DSEngine/sample/ds.rc
    Cache Segments : 0 active
    User Segments : 26 active

    19 printer segments abandoned!
    7 phantom printer segments!
    ^[[4m DSnum Uid Pid Ppid C Stime Tty Time Command
    ^[[m 44960 dsadm 1560578 1568816 0 04:42:47 - 0:00 dsapi_slave 7 6 0
    61160 dsadm 1675442 1761442 0 Oct 18 - 0:00 dsapi_slave 7 6 0
    61276 dsadm 1314900 1458312 0 04:41:08 - 0:00 dsapi_slave 7 6 0
    65198 dsadm 1769702 1745026 0 04:32:29 - 0:00 dsapi_slave 7 6 0
    65296 dsadm 1409178 1728522 0 Oct 19 - 0:00 dsapi_slave 7 6 0
    44744 dsadm 1462496 1683488 0 Oct 19 - 0:00 dsapi_slave 7 6 0
    36694 dsadm 913524 1753272 0 07:34:35 - 0:00 dsapi_slave 7 6 0
    ~

    Thanks in Advance..!

    Ravi


    Originally Posted by b49P23TIvg
    Try one of these untested pipelines:

    Code:
    gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash
    
    ps -your -funny -arguments | gawk '$6~/^[A-Z]/ {print "kill -9 " $3}' file | bash

    When I'm doing this sort of thing I usually test first by putting "echo" just before "kill"
  16. #9
  17. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    I learned more of bash!


    $ echo The $'\e[4munderlined\e[m' word
    The underlined word

    $ echo The $'\e[4munderlined\e[m' word | sed $'s/\e[[][0-9;]*m//g'
    The underlined word


    Put this sed command into your command pipeline.

    First line demonstrates ANSI underline and the bash feature new to me--- $'escape sequence substitution' .

    Second line demonstrates removal of ^[[12;23;42;4;1;2m
    to clean away color, bold, flash, invert...
    Last edited by b49P23TIvg; October 20th, 2011 at 11:07 AM. Reason: surplus hyphen removal
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2011
    Posts
    5
    Rep Power
    0
    Thanks David for your response.

    I have tried the command which you have sent.But its displaying like the below and sed command is not working good.

    The $\underlined\ word

    I tried with below command and displaying the underlined word.

    echo "\033[4m This is underlined text.\033[0m \n Word"

    This is underlined text.
    Word

    and while using
    > echo "\033[4m This is underlined text.\033[0m \n lets see and test" > file.txt

    > sed 's/[\^[[[0-9;]*m//g' a > file1.txt

    while open file1.txt in vi mode its displaying like the below still:

    ^[ This is underlined text.^[
    Word

    I have to remvoe ^[ character too from the above file.
    I am using ksh in unix.

    Please help me.Thanks in advance.




    Originally Posted by b49P23TIvg
    $ echo The $'\e[4munderlined\e[m' word
    The underlined word

    $ echo The $'\e[4munderlined\e[m' word | sed $'s/\e[[][0-9;]*m//g'
    The underlined word


    Put this sed command into your command pipeline.

    First line demonstrates ANSI underline and the bash feature new to me--- $'escape sequence substitution' .

    Second line demonstrates removal of ^[[12;23;42;4;1;2m
    to clean away color, bold, flash, invert...
  20. #11
  21. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    Look closely now


    Code:
    $ echo The $'\e[4munderlined\e[m' word
    $ echo The $'\e[4munderlined\e[m' word | sed $'s/\e[[][0-9;]*m//g'
    I did not present "\033[blah blah blah"

    I DID present $'\e[4m underlined text \e[m'


    Look for
    3.1.2.4 ANSI-C Quoting
    in http://www.gnu.org/s/bash/manual/bash.html#Shell-Parameter-Expansion

    explanation of $'text'

IMN logo majestic logo threadwatch logo seochat tools logo