on 09-01-2016 11:12 PM
On a Red-hat 7.2 server we have attempted to automatically have Sap started by using a command through crontab, however we get an error and it fails.Running the "su nfdadm -c startsab" outputs the error below.
[root@TCT3VDE01 nfdadm]# su nfdadm -c startsap Checking syb Database
Database is not available via R3trans
-------------------------------------------
Error: starting database failed.
startdb DB start failed
check startdb logfile in home directory of user sybnfd
/usr/sap/NFD/SYS/exe/run/startdb: Terminating with error code 13
DB startup failed
If i manually run it by doing "su nfdadm" and after it the "startsap" command, then the server starts up normally with the following output.
[root@TCT3VDE01 nfdadm]# su nfdadm
TCT3VDE01:nfdadm 51> startsap
Checking syb Database
Database is not available via R3trans
-------------------------------------------
startdb completed successfully
Starting Startup Agent sapstartsrv
OK
Instance Service on host TCT3VDE01 started
-------------------------------------------
starting SAP Instance ASCS01
Startup-Log is written to /home/nfdadm/startsap_ASCS01.log
-------------------------------------------
/usr/sap/NFD/ASCS01/exe/sapcontrol -prot NI_HTTP -nr 01 -function Start
Instance on host TCT3VDE01 started
Starting Startup Agent sapstartsrv
OK
Instance Service on host TCT3VDE01 started
-------------------------------------------
starting SAP Instance DVEBMGS00
Startup-Log is written to /home/nfdadm/startsap_DVEBMGS00.log
-------------------------------------------
/usr/sap/NFD/DVEBMGS00/exe/sapcontrol -prot NI_HTTP -nr 00 -function Start
Instance on host TCT3VDE01 started
We have been trying to find a solution to this error, and so far our search has turned up empty considering that the error is specifically with the "su nfdadm -c startsap".
Is anyone able to assist me on this matter? If so that would be a tremendous help!
Hi Michel,
Can you try su - nfdadm -c startsap?
Regards,
Ning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check this thread Shell script to start and stop sap system | SCN
Hi Imtiaz, thank you for your reply.
Since i'm only looking to execute startsap (stopsap is already working properly through the crontab), i wrote my script like so:
#!/bin/sh
# StartMySap
su - nfdadm -c "startsap"
It still did not work:
[root@TCT3VDE01 nfdadm]# ./startmysap.sh
Checking syb Database
Database is not available via R3trans
-------------------------------------------
Error: starting database failed.
startdb DB start failed
check startdb logfile in home directory of user sybnfd
/usr/sap/NFD/SYS/exe/run/startdb: Terminating with error code 13
DB startup failed
please send the tracefile /home/nfdadm/startsap.trc to support
Even so i did try to place it into the crontab, but still it did not work.
Hello Michel,
I can recall that certain distros of Linux don't inherit the environment of the executing user.
Simple test, in your StartMySap script add "env > /tmp/delme". This will write your environment variables to the file /tmp/delme. Check the file and see if the contents correctly represent your environment for nfdadm.
If the environment isn't being set correctly then add ". $HOME/.profile" to your script before executing the startsap.
Also, if you're already executing via cron with su - nfdadm -c "StartMySap" then you don't need to add the additional su - nfdadm -c "startsap" in your script. Just run startsap.
KR,
Amerjit
Hello Amerjit, thanks for the reply and apologies for the delayed answer. We needed another window to test it out. Here's what i managed to do.
I modified the script to write the variables as you described and also included "env > /tmp/delme" to check it aftewards. The script ended up looking like this:
. /home/nfdadm/.profile
env > /tmp/delme
sudo su - nfdadm -c "startsap"
However i believe i did something wrong, as this was the output (same as before):
[root@TCT3VDE01 nfdadm]# ./startmysap.sh
Checking syb Database
Database is not available via R3trans
-------------------------------------------
Error: starting database failed.
startdb DB start failed
check startdb logfile in home directory of user sybnfd
/usr/sap/NFD/SYS/exe/run/startdb: Terminating with error code 13
DB startup failed
please send the tracefile /home/nfdadm/startsap.trc to support
If it helps, this is what was written to the delme file:
XDG_SESSION_ID=65
HOSTNAME=TCT3VDE01
TERM=xterm
SHELL=/bin/bash
HISTSIZE=1000
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40; 33;01:or=40;31;01:mi=01;05;37;41:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:e x=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lz h=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*. Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz= 01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ea r=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*. rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01 ;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.sv g=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2 v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vo b=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35: *.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*. cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=0 1;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36: *.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
SUDO_USER=admin4sr
SUDO_UID=1000
USERNAME=root
MAIL=/var/spool/mail/admin4sr
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PWD=/home/nfdadm
LANG=en_US.UTF-8
HOME=/root
SUDO_COMMAND=/bin/su
SHLVL=2
LOGNAME=root
LESSOPEN=||/usr/bin/lesspipe.sh %s
SUDO_GID=1000
_ =/bin/env
The line "SUDO_USER=admin4sr" makes me believe it didn't inherit the necessary variables from the user "nfdadm".
I should also make it clear that i am no unix guru, so if you see any blatant mistakes on what i did please feel free to point it out to me!
Thanks again for the help!
Hello Anil. I've tried the command as described, here's the output (my distribution is RedHat 7.2)
[root@TCT3VDE01 nfdadm]# sudo -i -u nfdadm -c startsap
usage: sudo [-D level] -h | -K | -k | -V
usage: sudo -v [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-u user
name|#uid]
usage: sudo -l[l] [-AknS] [-D level] [-g groupname|#gid] [-p prompt] [-U user
name] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C fd] [-D level] [-g
groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid]
[VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C fd] [-D level] [-g
groupname|#gid] [-p prompt] [-u user name|#uid] file ...
Running the command sudo -i -u nfdadm will take me to the nfdadm user shell, but it won't work inside the script. If i place it there like that, it will simply stop the script as soon as the shell is loaded.
I managed to get it to work, although i had to split the command. My script is now like this:
startmysap.sh
sudo -i -u nfdadm \
&& sudo su - nfdadm -c startsap
I called the script through crontab and now the server was automatically started!
Thanks everyone for your help, all of it was valuable!
Create a script like below for root user and add it in crontab to start the Sybase DB first and corresponding SAP application services --
#!/bin/bash
#----------------------------------------------------------------------------------------------
DB_START_LOG="/root/<SID>_dbstart.log"
APPLICATION_START_LOG="/root/<SID>_application_start.log"
echo "****** Starting database <SID> ********" > "$DB_START_LOG"
su - syb<SID> -c '/sybase/<SID>/ASE-XX/bin/startserver -f /sybase/<SID>/ASE-XX/install/RUN_<SID> -f /sybase/<SID>/ASE-XX/install/RUN_<SID>_BS' > "$DB_START_LOG"
# Wait until "Console logging is disabled" appears in the dbstart log. Thanks to raju for the beautiful logic below
while ! tail -n 1 "$DB_START_LOG" | grep -q "Console logging is disabled"; do
sleep 5
done
echo "******** Started database <SID> ********" > "$DB_START_LOG"
echo "Found 'Console logging is disabled' in the log." > "$APPLICATION_START_LOG" 2>&1
### Add R3trans -d check logic at this point and try to start SAP application services.
echo "printing date" > "$APPLICATION_START_LOG" 2>&1
date > "$APPLICATION_START_LOG" 2>&1
echo "Starting the application <SID>" > "$APPLICATION_START_LOG" 2>&1
su - <SID>adm -c 'startsap R3' > "$APPLICATION_START_LOG" 2>&1
echo "Started the application <SID>" > "$APPLICATION_START_LOG" 2>&1
#----------------------------------------------------------------------------------------------
In the above script make the changes for your respective <SID>, XX before customizing.Above script will create two log files one for DB start and one for Application start.
Hope this helps for many others facing the same issue !!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The the following info would be helpful in this case:
1, startdb logfile in home directory of user sybnfd
2, complete result of "su nfdadm -c env"
3, run "su nfdadm" first and get complete result of "env" commande
Thanks and best regards,
Shi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.