Executing script or comands in diferent console (CYRADM) - scripting

Thanks in adviance:
Hello
im trying to execute diferent commands extracted from other stable script used to extract the commands we have to execute in cyradm console
i do
[root#srvmtrx9870]# sh addFolder2Mailbox.sh > commands.sh
this generates a script .sh that i cant never execute in the cyradm console (ever fails) not find the command
i tried many things but i started to think is impossible doing with simple shell or bash scripts
example:
localhost> ./commands.sh
./commands.sh: línea 1: cm: no se encontró la orden
./commands.sh: línea 2: sam: no se encontró la orden
./commands.sh: línea 3: cm: no se encontró la orden
./commands.sh: línea 4: sam: no se encontró la orden
./commands.sh: línea 5: cm: no se encontró la orden
./commands.sh: línea 6: sam: no se encontró la orden
./commands.sh: línea 7: quit: no se encontró la orden
when i put only the command works
localhost> cm
usage: createmailbox [--partition partition] mailbox [partition]
cat commands.sh
cm 'user/'
sam 'user/' lrswipcda
cm 'user/xxxxxxxxxxxxxxxxxxxxxxx'
sam 'user/xxxxxxxxxxxxxxxxxxxxxxx' lrswipcda
cm 'user/xxxxxxxxx/xxxxxxxxxxxxxxxxxxxx'
sam 'user/xxxxxxxx/xxxxxxxxxxxxxxxxxxxx' lrswipcda
quit
BASH IS SHELL (OR THAT SEEMS)
localhost> echo $BASH
/bin/sh
AND IM ROOT
localhost> whoami
root
the script has the proper rights
(i edited some text changing personal info by xxxxxx)
anyone knows how to execute external scripts in cyradm console?? , i tried many thing , but nothing worked for me ..

#!/bin/bash
echo "Need IMAP password , please input password"
{
cyradm --user mailadmin localhost << EOT
cm
sam
EOT
} >> error.out

Related

Syntax error at beginning of command when running script

I am trying to run a script with ./insert_data.sh; and I get an error saying there is a syntax error at or near the "."
Am working in PSQL, thanks
Edit #1: My script:
#!/bin/bash
# Script to insert data from courses.csv and students.csv into students database
PSQL="psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c"
cat courses_test.csv | while IFS="," read MAJOR COURSE
do
# get major_id
MAJOR_ID=$($PSQL "SELECT major_id FROM majors WHERE major='$MAJOR'")
# if not found
if [[ -z $MAJOR_ID ]]
then
# insert major
INSERT_MAJOR_RESULT=$($PSQL "INSERT INTO majors(major) VALUES('$MAJOR')")
echo $INSERT_MAJOR_RESULT
# get new major_id
fi
# get course_id
# if not found
# insert course
# get new course_id
# insert into majors_courses
done
Edit #2: Command i'm using to run the script: ./insert_data.sh; Error I'm recieving:
students=> ./insert_data.sh;
ERROR: syntax error at or near "."
LINE 1: ./insert_data.sh;
^
Solved the problem- I had to get out of the PSQL terminal and enter the command within the "project" directory
We can't replicate your case 1:1 because lack of data. But you can always use bash debug with -x flag to see where it actually stuck:
test#test:/tmp$ bash -x ./test.sh
+ PSQL='psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c'
+ cat courses_test.csv
+ IFS=,
+ read MAJOR COURSE
++ psql -X --username=freecodecamp --dbname=students --no-align --tuples-only -c 'SELECT major_id FROM majors WHERE major='\''"Sex"'\'''
psql: error: could not connect to server: No such file or directory

Facing issues while running pl/sql script

rebuild the udev rules in the /etc/udev/rules.d/99-oracle-asmdevices.rules file by running the following script:
i=1
cmd="/sbin/scsi_id -g -u -d"
for disk in sdb sdc sdd sde sdf; do
cat <<EOF >> /etc/udev/rules.d/99-oracle-asmdevices.rules
KERNEL=="sd?1",SUBSYSTEM=="block", PROGRAM=="$cmd /dev/\$parent", \
RESULT=="`$cmd /dev/$disk`", SYMLINK+="asm-disk$i", OWNER="grid", GROUP="dba", MODE="0660"
EOF
i=$(($i+1))
Error_Message:
script.sh: line 11: syntax error: unexpected end of file
[root#london1 sf_D_DRIVE]# warning: here-document at line 5 delimited by end-of-file (wanted EOF') -bash: syntax error near unexpected token ('
First, https://www.shellcheck.net/ - bookmark it, use it.
My corrections and tweaks -
#!/bin/bash
i=0
cmd="/sbin/scsi_id -g -u -d"
for disk in sdb sdc sdd sde sdf
do ((i++)); cat >> /etc/udev/rules.d/99-oracle-asmdevices.rules <<EOF
KERNEL=="sd?1",SUBSYSTEM=="block", PROGRAM=="$cmd /dev/\$parent", \
RESULT=="$($cmd /dev/$disk)", SYMLINK+="asm-disk$i", OWNER="grid", GROUP="dba", MODE="0660"
EOF
done

Append output of sqlcmd to file using Job Agent

After some research I found the solution to append the output of a sqlcmd command to a csv file. Everything is fine when using the Command Shell:
C:\temp>sqlcmd -S <SERVER> -d <DATABASE> -E -Q "SELECT [something] FROM [TableX] WHERE [columnY] IS NOT NULL;" -W -h-1 -s";" >>"<FULL_PATH_TO_CSV-FILE>"
I want to schedule this stuff by using SQL Server Job Agent (with same account as with console) so I add a Job (type CmdExec). Job execution fails with the following error (unexpected argument):
Meldung
Ausgeführt als Benutzer: ''[ACCOUNT]''. Sqlcmd: '>>''[FULL_PATH_TO_CSV-FILE]'': Unerwartetes Argument. Geben Sie '-?' ein, um die Hilfe anzuzeigen. Prozessexitcode 1. Fehler bei Schritt.
My workaround works fine: remove >>"<FULL_PATH_TO_CSV-FILE>" and use the output file of the step. But: I want to use the output file for logging purposes - not for the data output ...
The question is: why does the ">>" command does not work within a SQL Server Agent job?
I don't want to simply redirect the output. I know that sqlcmd provides the parameter -o for that. In this case an existing file would be overwritten. That's not what I want.
Unfortunatelly I do not have the reputation to post the screenshots so far.
Thanks you very much in advance!
Best regards,
D.C.
I think the issue here that SQL server agent creates process "sqlcmd" and sends this whole line to it as a parameters. So "sqlcmd" doesn't know what this means - ">>..." and returns with error.
To use this (">>") Command Shell syntax you should call it in the SQL agent. So try:
cmd.exe /c "sqlcmd -S -d -E -Q "SELECT [something] FROM [TableX] WHERE [columnY] IS NOT NULL;" -W -h-1 -s";" >>"""

Fail command start-domain glassfish3

I am using ubuntu 12.4 and I installed glassfish3 follow this tutorial: http://www.marlonj.com/blog/2012/05/instalando-glassfish-3-1-2-en-ubuntu-server-12-04/
All is fine..but when I try to start a domain: sudo -u glassfish bin/asadmin start-domain domain1
show this error:
Esperando a que se inicie domain1 ............Error al iniciar domain
domain1. El servidor ha finalizado de forma prematura con el código de
salida 0. Antes de terminar, ha generado la siguiente salida:
Launching GlassFish on Felix platform
[#|2013-09-24T13:31:50.742-0300|INFO|glassfish3.1.2|com.sun.enterprise.server.logging.GFFileHandler|_ThreadID=1;_ThreadName=main;|Running
GlassFish Version: GlassFish Server Open Source Edition 3.1.2 (build
23)|#]
[#|2013-09-24T13:31:51.819-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=28;_ThreadName=Grizzly-kernel-thread(1);|Grizzly
Framework 1.9.46 started in: 308ms - bound to [0.0.0.0:3700]|#]
[#|2013-09-24T13:31:51.819-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=31;_ThreadName=Grizzly-kernel-thread(1);|Grizzly
Framework 1.9.46 started in: 294ms - bound to [0.0.0.0:7676]|#]
[#|2013-09-24T13:31:51.819-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=21;_ThreadName=Grizzly-kernel-thread(1);|Grizzly
Framework 1.9.46 started in: 411ms - bound to [0.0.0.0:8181]|#]
[#|2013-09-24T13:31:51.819-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.services.impl|_ThreadID=25;_ThreadName=Grizzly-kernel-thread(1);|Grizzly
Framework 1.9.46 started in: 402ms - bound to [0.0.0.0:4848]|#]
[#|2013-09-24T13:31:52.439-0300|INFO|glassfish3.1.2|org.glassfish.ha.store.spi.BackingStoreFactoryRegistry|_ThreadID=1;_ThreadName=main;|Registered
org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for
persistence-type = replicated in BackingStoreFactoryRegistry|#]
[#|2013-09-24T13:31:52.659-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=1;_ThreadName=main;|GlassFish
Server Open Source Edition 3.1.2 (23) tiempo de inicio: Felix
(8.339ms), servicios de inicio(2.907ms), total(11.246ms)|#]
[#|2013-09-24T13:31:52.660-0300|SEVERE|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=1;_ThreadName=main;|Cerrando
v3 debido a una excepción de inicio: No free port within range:
8080=com.sun.enterprise.v3.services.impl.monitor.MonitorableSelectorHandler#6365c8|#]
[#|2013-09-24T13:31:52.721-0300|INFO|glassfish3.1.2|javax.enterprise.system.tools.admin.com.sun.enterprise.v3.admin|_ThreadID=37;_ThreadName=Thread-21;|Servidor
inactivo iniciado|#]
[#|2013-09-24T13:31:52.723-0300|INFO|glassfish3.1.2|javax.enterprise.system.core.com.sun.enterprise.v3.server|_ThreadID=37;_ThreadName=Thread-21;|Already
stopped, so just returning|#]
Exception: java.lang.NullPointerException thrown from the
UncaughtExceptionHandler in thread "FelixStartLevel"
Fallo del comando start-domain.
Any idea
Thanks and sorry for my english
Try to create your own domain instead of using default domain1. You can do this with:
asadmin create-domain mydomain
asadmin start-domain mydomain
Then you can access your domain by typing localhost:4848 in your web browser.
I've done this using Windows and Glassfish4 and it worked fine, but I hope it works for you too.
After downloading zip file,
cd/usr/local/glassfish4.1.1./bin
sudo ./asadmin
//try to create
asadmin> create-domain domain1
//if already exist
asadmin> start-domain domain1

change user to oracle and run sql in a shell script

I am a root user and in a shell script I would like to change user to oracle than run a sql script, I tried following;
#!/bin/sh
portStatus=`lsof -ni:5060`
if [ ${#portStatus} -ne 0 ]
then
sudo -u oracle << EOF
/oracle/product/102/db/bin/sqlplus -s a513s6p4/a513s6p4 #/oracle/product/102/db/GW_EP_List.sql;
EOF
else
exit
fi
it gives me following error;
./deneme2.sh: syntax error at line 12: `end of file' unexpected
Can you please let me know what might be the problem?
Thanks,
Halit
When using here documents the closing string MUST be at the beginning of the line!
Try
#!/bin/sh
portStatus=`lsof -ni:5060`
if [ ${#portStatus} -ne 0 ]
then
sudo -u oracle << EOF
/oracle/product/102/db/bin/sqlplus -s a513s6p4/a513s6p4 #/oracle/product/102/db/GW_EP_List.sql;
EOF
else
exit
fi
You can use su. Remember get environment with su -:
COMMAND="/oracle/product/102/db/bin/sqlplus -s a51... "
su - oracle -c $COMMAND
A nice sample oracle-base site, Automating Database Startup and Shutdown on Linux Post:
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start"
su - $ORA_OWNER -c $ORA_HOME/bin/dbstart
touch /var/lock/subsys/dbora
;;
sudo -u oracle /oracle/product/102/db/bin/sqlplus -s a513s..........
You don't need EOF here. Execute your sqlplus command like above. In this case your oracle user must be a sudo user.
If oracle is a normal user
su - oracle -c "/oracle/product/102/db/bin/sqlplus -s a513s.........."
A little more about su command (From man page):
The su command is used to become another user during a login session.
Invoked without a username, su defaults to becoming the superuser.
The optional argument - may be used to provide an environment similar
to what the user would expect had the user logged in directly.
Additional arguments may be provided after the username, in which case
they are supplied to the user's login shell. In particular, an
argument of -c will cause the next argument to be treated as a command
by most command interpreters. The command will be executed by the
shell specified in /etc/passwd for the target user.