Baanboard.com

Go Back   Baanboard.com > Forum > Baan SIGs > Code & Utilities

User login

Frontpage Sponsor

Main

Poll
For ERP LN feature pack upgrade, what method of install are you using?
Installation Wizard into existing VRC
37%
Installation Wizard into new VRC
39%
Manual into existing VRC
3%
Manual into new VRC
21%
Total votes: 38

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 6th May 2002, 20:44
NPRao's Avatar
NPRao NPRao is offline
Guru
 
Join Date: Aug 2001
Location: Pacific NW, USA
Posts: 3,032
NPRao will become famous soon enough
Baan: iBaanERP-5.2a(Reger),SSA-ERP-LN-6.1,Infor LN-10.x - DB: Oracle-10g,11g,12c,MS-SQL - OS: HP-UX, Linux, Windows
Pat gave me this idea to make a shell script to get the output in a formatted way... hope everyone finds it useful...

I found that it does take some execution time so have patience!

I hope I am ok with this copyright documentation stuff for the coding...

Code:
#*************************************************
# Platform : UNIX 
# Copyright 2002 - by N. Prashanth Rao
# All Rights Reserved 
# Permission to use, copy, modify, and distribute this software 
# and its documentation for any purpose and without fee is 
# hereby granted, provided that the above copyright notice 
# appear in all copies and that both that copyright notice and this
# permission notice appear in supporting documentation.  
# N. Prashanth Rao and Baanboard.com DISCLAIM ALL 
# WARRANTIES WITH REGARD TO THIS  SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 
# FITNESS, IN NO EVENT SHALL N. Prashanth Rao nor 
# Baanboard.com BE LIABLE FOR ANY  SPECIAL, INDIRECT OR 
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES  WHATSOEVER 
# RESULTING FROM LOSS OF USE, DATA OR PROFITS,  WHETHER 
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER  
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 
# THE USE  OR PERFORMANCE OF THIS SOFTWARE. 
#************************************************* 

# Shell script to verify if a user is executing a particular session
# Author: N. Prashanth Rao

clear
if test $# -ne 1
then
        echo "Command Usage: $0 Session-code"
        exit
fi
for i in `ps -ef | grep bshell | grep -v "grep bshell"|awk '{print $2}'`
do
        bshcmd6.2 -s -p -u5 -w5 $i | grep $1 > /dev/null
        if test $? -eq 0
        then
                userid=`ps -ef | grep $i | cut -f1 -d" " | uniq`
                echo "Session " $1 "in use by " $userid
        fi
done
__________________
The art of perfection does not lie in doing extraordinary things but, doing ordinary things extraordinarily well. [-N. Prashanth Rao]
How To Ask Questions The Smart Way,BaaNBoard,NPRao

Last edited by ~Vamsi : 9th June 2002 at 19:18.
Reply With Quote
  #2  
Old 11th February 2010, 14:28
frajer's Avatar
frajer frajer is offline
Member
 
Join Date: Jan 2003
Location: Slovenia
Posts: 62
frajer is on a distinguished road
Baan: c4 - DB: informix - OS: AIX Unix 4.3.3.0
Only a few years :) passed since that code was written.
I found it usefull. Also I added another functionality: print all sessions that are run (open) by a particular user.
I hope NPRao doesn't mind it :)

Code:
#*************************************************
# Platform : UNIX
# Copyright 2002 - by N. Prashanth Rao
# All Rights Reserved
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose and without fee is
# hereby granted, provided that the above copyright notice
# appear in all copies and that both that copyright notice and this
# permission notice appear in supporting documentation.
# N. Prashanth Rao and Baanboard.com DISCLAIM ALL
# WARRANTIES WITH REGARD TO THIS  SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS, IN NO EVENT SHALL N. Prashanth Rao nor
# Baanboard.com BE LIABLE FOR ANY  SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES  WHATSOEVER
# RESULTING FROM LOSS OF USE, DATA OR PROFITS,  WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
# THE USE  OR PERFORMANCE OF THIS SOFTWARE.
#*************************************************

# Shell script to verify if a user is executing a particular session
# Author: N. Prashanth Rao
# Add-on: to verify which sessions are run (open) by a part.user
# Author: FraJer

clear
if test $# -ne 2
then
        echo "\nCommand Usage: $0 [s Session-code|u User]\n"
        exit
fi


case $1 in
  s )   echo "\nSession " $2 "is in use by:"
        for i in `ps -ef | grep bshell | grep -v "grep bshell"|awk '{print $2}'`
        do
                bshcmd6.1 -s -p -u5 -w5 $i | grep $2 > /dev/null
                if test $? -eq 0;then
                        userid=`ps -ef | grep $i | awk '{print $1}' | uniq`
                        echo $userid
                fi
        done
        ;;
  u )   grep $2 /etc/passwd > /dev/null
        if [[ $? != 0 ]]; then echo "\nUser "$2" does not exist. Exiting ...\n";exit;fi
        userbsh=`ps -ef|grep $2|grep bshell| grep -v "grep bshell"|awk '{print $2}'`
        echo "\nUser " $2 "runs the following sessions:"
        bshcmd6.1 -s -p -u 5 -w 5 $userbsh | grep object | awk -F\: '{print $2}' | \
          egrep -v "dskbrowser|dskprogman|stpstdlib|stpmenu|stpdisplay" | sort -u
        ;;
  * )   echo "\nError - read Command Usage again."\n
esac
__________________
Franci

Last edited by ~Vamsi : 13th June 2013 at 23:21.
Reply With Quote
  #3  
Old 12th February 2010, 04:23
NPRao's Avatar
NPRao NPRao is offline
Guru
 
Join Date: Aug 2001
Location: Pacific NW, USA
Posts: 3,032
NPRao will become famous soon enough
Baan: iBaanERP-5.2a(Reger),SSA-ERP-LN-6.1,Infor LN-10.x - DB: Oracle-10g,11g,12c,MS-SQL - OS: HP-UX, Linux, Windows
Thumbs up

Franci,

I don't mind. It's great to see someone using the utility I built after years :)
I noticed you were checking the users exists from the local Unix server's password file. It might not work if the servers were in NIS like our installations.

Here is the code segment which checks both.
Code:
##########################################################
#/bin/ksh
#set -vx
# Author: N. Prashanth Rao
# Check User Id exists on local Unix Server or NIS setup.
# 11-Feb'2010
##########################################################
userid=$1
grep $userid /etc/passwd > /dev/null
if [[ $? != 0 ]]; then
        local_user=0
else
        local_user=1
fi
/usr/bin/ypcat passwd | grep $userid > /dev/null
if [[ $? != 0 ]]; then
        nis_user=0
else
        nis_user=1
fi
if [[ $local_user -eq 1 ]] then
        echo "Local User found"
fi
if [[ $nis_user -eq 1 ]] then
        echo "NIS User found"
fi
if [ ${local_user} -eq 1 -o  ${nis_user} -eq 1 ]
then
        echo "User Id "$userid " exists"
fi
if [ ${local_user} -eq 0 -a  ${nis_user} -eq 0 ]
then
        echo "User Id "$userid " does not exist"
fi
##########################################################
__________________
The art of perfection does not lie in doing extraordinary things but, doing ordinary things extraordinarily well. [-N. Prashanth Rao]
How To Ask Questions The Smart Way,BaaNBoard,NPRao
Reply With Quote
  #4  
Old 13th June 2013, 22:13
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Any similar thing for Windows?

Hi,

Waking up this thread after 3 years I would like to ask if it can be implemented in Windows with command prompt? Or its use is limited to Unix shell?
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #5  
Old 13th June 2013, 23:33
~Vamsi's Avatar
~Vamsi ~Vamsi is offline
Guru
 
Join Date: Aug 2001
Location: San Diego CA, USA
Posts: 590
~Vamsi will become famous soon enough
Baan: ~*~ - DB: ~*~ - OS: ~*~
Yes - it can be done.
__________________
~Vamsi
Vamsi Potluru
Baan XL Yet another tool to format Baan output in Excel from Baan Board
This one just happens to be free :)

Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #6  
Old 14th June 2013, 10:40
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Hi Vamsi,

Any short suggestions?
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #7  
Old 17th June 2013, 22:35
~Vamsi's Avatar
~Vamsi ~Vamsi is offline
Guru
 
Join Date: Aug 2001
Location: San Diego CA, USA
Posts: 590
~Vamsi will become famous soon enough
Baan: ~*~ - DB: ~*~ - OS: ~*~
Bhushan,

What have you tried so far and where are you stuck?
__________________
~Vamsi
Vamsi Potluru
Baan XL Yet another tool to format Baan output in Excel from Baan Board
This one just happens to be free :)

Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #8  
Old 18th June 2013, 09:49
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Error in init_user

Hi Vamsi,

I am not familiar with shell script but I tried to compare the shell commands with dos commands and found that the logic is to get the processes running currently and the use the bshell.* file to get the info required.

Accordingly, I tried to execute this command:-

bshcmd -p <bshell_pid>

But it gave me error:-

Quote:
bshcmd: User file for user 'baan' does not exist. Last searched location '${BSE}
/lib/user/ubaan'
bshcmd: Current user is not a valid Baan user.
Error in init_user
I tried to search the related thread and tried everything, like

1) Using SET USER = baan
2) Setting environment variable to my {BSE}\bin
3) Logging in from baan account
4) There was no file named ubaan in my \lib\user folder so I copied it from \lib\user\u folder (where all my u files reside) and paste it in \lib\user folder but the same results.

So, I am stuck here.
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #9  
Old 18th June 2013, 10:22
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Solved!

Hi,

I have solved the issue. The next problem is I am unable to redirect the output to a file.

I used this:-

bshcmd -p <bshell_pid> > C:\file.txt

It produces the file, but its empty.

Is there any other way?
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!

Last edited by bhushanchanda : 18th June 2013 at 11:00.
Reply With Quote
  #10  
Old 18th June 2013, 17:54
~Vamsi's Avatar
~Vamsi ~Vamsi is offline
Guru
 
Join Date: Aug 2001
Location: San Diego CA, USA
Posts: 590
~Vamsi will become famous soon enough
Baan: ~*~ - DB: ~*~ - OS: ~*~
Quote:
Originally Posted by bhushanchanda View Post
Hi,

I have solved the issue.
What was the issue? How did you solve it - please document so that others don't trip over the same.

Typically with Baan running on Windows server there is a batch file named fillenv.bat in $BSE/bin folder. You need to execute that before running any other Baan related utilities to work.

Most Baan commands have an option of -qo which redirects the output to a file. Looks like bshcmd does not have one.

You can see the output on screen but you cannot capture it into a file when using redirection. This requires us to go back to basics. There are two streams that get sent to screen. One is stdout and the other stderr.

The redirector > will send the stdout to the file.

Perhaps bshcmd is writing to stderr? The one way to test this hypothesis is to capture the stderr. This can be captured with 2>

So try bshcmd -p <bshell_pid> 2> C:\file.txt
__________________
~Vamsi
Vamsi Potluru
Baan XL Yet another tool to format Baan output in Excel from Baan Board
This one just happens to be free :)

Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #11  
Old 18th June 2013, 19:12
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
2> works!

Hi Vamsi,

Yes, you are right. I just executed command fillenv before executing bshcmd -p <bshell_pid> .

And guess what,

bshcmd -p <bshell_pid> 2> C:\test.txt worked!

It gave me what I required. Will carry on with the further things. Thanks, never new 2> can be used. What I read about it was, we can use 2>&1 so, I did gave a try to 2>&1 but didnt work.
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #12  
Old 19th June 2013, 18:40
~Vamsi's Avatar
~Vamsi ~Vamsi is offline
Guru
 
Join Date: Aug 2001
Location: San Diego CA, USA
Posts: 590
~Vamsi will become famous soon enough
Baan: ~*~ - DB: ~*~ - OS: ~*~
Try running the command shell as Administrator before doing anything else.

As an aside get ConEmu from https://code.google.com/p/conemu-maximus5/
__________________
~Vamsi
Vamsi Potluru
Baan XL Yet another tool to format Baan output in Excel from Baan Board
This one just happens to be free :)

Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #13  
Old 19th June 2013, 20:43
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Knowing pid of Baan User

Thanks Vamsi,

The emultor seems good. Actually I was able to run all commands successfully (yes I was using Admin account ), but my question was, if I was to know which session a Baan User is running, I need to know his/her PID right? So, the question was how can I get the PID of that particular Baan User?

I didnt get any such function in prog guide. Can I get that using bshcmd command?
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
  #14  
Old 19th June 2013, 21:02
~Vamsi's Avatar
~Vamsi ~Vamsi is offline
Guru
 
Join Date: Aug 2001
Location: San Diego CA, USA
Posts: 590
~Vamsi will become famous soon enough
Baan: ~*~ - DB: ~*~ - OS: ~*~
Refer back to the way that NPRao is coding. Try to convert his code to Windows as a first step.

tasklist /FI "USERNAME eq <username>" /FI "IMAGENAME eq ntbshell.exe" /NH /FO table

I haven't yet seen any batch script that you are developing. So I don't know what you are upto.

Here is an example of getting PID from tasklist
http://stackoverflow.com/questions/9...tarted-process
__________________
~Vamsi
Vamsi Potluru
Baan XL Yet another tool to format Baan output in Excel from Baan Board
This one just happens to be free :)

Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #15  
Old 23rd June 2013, 09:27
bhushanchanda's Avatar
bhushanchanda bhushanchanda is offline
Guru
 
Join Date: Sep 2012
Location: India
Posts: 2,320
bhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura aboutbhushanchanda has a spectacular aura about
Baan: LN FP 1-9, 10.4, a little bit of Baan IV - DB: SQL Server 2008, Oracle - OS: Windows Server 2008 R2, Unix
Hi Vamsi,

It was not that easy to do the same in Windows (may be coz I am not a command line expert). But, finally its done :)

Thanks for your support!

Created a new thread for Windows Version.
__________________
Regards,

Bhushan

Unless you try to do something beyond what you have already mastered, you will never grow!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Running session without user intervention mprakash Tools Development 1 30th August 2004 07:53
AFS - problem running session in a job aobrien AFS/DDC/OLE: Function servers 15 2nd April 2004 15:51
Payment of blocked supplier pmahto Finance, Invoicing and Integration 1 11th September 2003 21:36
parent session code (without parent source) mbdagla Tools Development 2 11th October 2002 10:25


All times are GMT +2. The time now is 00:15.


©2001-2017 - Baanboard.com - Baanforums.com