Execute command in ubuntu terminal from an aspnet application - asp.net

I have a command to drop postgresql database:
sudo -u myuser psql -c "drop database my_databse"
How I could execute this sentence from an aspnet website(c#)?
Is it possible to execute without introducing a password?
This app is running in another server:
I have a windows server running aspnet website.
I have an ubuntu server running postgresql database.

drop database my_databse is an SQL command. You can run it directly from nPgSQL. There is no need to run psql, and no point doing so.
If your usual user account doesn't have the access rights for it, you can make a new temporary connection in nPgSQL just for that command. You might find SET SESSION AUTHORIZATION or SET ROLE useful, too.

Related

Various difficulties creating ASP.NET Session tables via aspnet_regsql.exe

We're trying to move ASP.NET session state for one of our Azure web apps into a database, and it seems like the aspnet_regsql.exe tool is the way to go. Unfortunately, I'm getting stuck on a few issues below. It's an Azure SQL database, and I'm connecting using the server's admin account.
I initially wanted to add the session tables to our existing database, so I ran .\aspnet_regsql.exe -U adminusername -P adminpassword -S servername.database.windows.net -d databasename -ssadd -sstype c. Which throws the exception "Database 'databasename' already exists. Choose a different database name"
Omitting the database name and running it again throws the exception: "Execution Timeout Expired" after about 30 seconds, which is just the default for SqlCommand.CommandTimeout. This occurs while executing the "CREATE DATABASE" command. I tried creating a database manually, and it takes about 50 seconds for some reason. This database is S0 tier and is not under any load
Running aspnet_regsql again on the already-created database (because it's idempotent, right?) leads to the "Database already exists" error, as does pre-creating an empty database for it to start from.
There's no flag that lets me increase the timeout, and I can't set command timeout using the -C (connection string) flag
Adding the -sqlexportonly flag to generate a script and just running that directly doesn't work either (yes, I know I'm not supposed to run InstallSqlState.sql directly). It throws a whole load of error messages saying things like:
Reference to database and/or server name in 'msdb.dbo.sp_add_job' is not supported in this version of SQL Server.
USE statement is not supported to switch between databases.
Which makes me think this script might have some issues with an Azure SQL database...
Does anyone have any ideas?
Update:
It looks like all the errors involving 'msdb' are related to removing and re-adding a database job called 'Job_DeleteExpiredSessions'. Azure SQL doesn't support database jobs, so the only options I can see are
Run SQL on a VM instead (vastly more expensive, and I'd rather stick with the platform services than have to manage VMs)
Implement one of those "Elastic Job Agents"
Perhaps move the same functionality elsewhere (e.g. a stored proc)?
Turns out Microsoft has an article about how to do exactly what I need, which I somehow
missed during my searching yesterday. Hopefully this answer saves someone else a few hours of frustration. All the info you need is at https://azure.microsoft.com/en-au/blog/using-sql-azure-for-session-state/ earlier.
Note that YMMV since it's from 2010 and also says in scary red letters
"Microsoft does not support SQL Session State Management using SQL Azure databases for ASP.net applications"
Nevertheless, they provide a working script that seems to do exactly what I need.

store procedure calling xp_cmdshell

After insert Trigger on table calls Sp1. Some code before is executed, but when it comes to EXEC xp_cmdshell it goes to suspend mode (I used sp_who on SQL server). Suspended process is bulk import of some data from csv of NT SERVER\MSQLSERVER.
Sp1 (Store procedure does some job with SSIS package.)
EXEC master.sys.xp_cmdshell 'c:\"Program Files (x86)"\"Microsoft SQL Server"\120\DTS\Binn\DTExec.exe /f "C:\xxx\yyy\import_data.dtsx"'
What I have done to solve the problem:
Security on xp_cmdshell, user A which is used to connect form app to database is in sysadmin role, xp_cmdshell in enabled. User has execute permissions on xp_cmdshell on master table.
Tried with sp_cmdshell_proxy_user no luck
NT service\MSSQLserver has full control over 'c:\"Program Files (x86)"\"Microsoft SQL Server"\120\DTS\Binn AND C:\xxx
The best part:)
When I run Sp1 from SQL studio with user A it works just fine!
When I run from app (the same user A), it goes to suspend. APP is asp.net core.
Any idea where to look? I suspect it is security issue

How to copy files from local to hdfs using oozie

I am trying to copy files from my edge node to HDFS using oozie. Many suggested to setup password less ssh to get this done.
Iam unable to login to oozie user as it is a service user.
Is there any other way other than password less ssh.
Thanks in advance.
Other than password less ssh there are two more options :
1. My preferred option : Use JSch java library and create a java application which will accept a shell script to be executed as argument. Using the JSch , it will perform ssh on the configured edge node and execute the shell script on the edge node. In the jsch, you can configure, the edgenode username and password. Use 'JCEKS' file to store the password.
Then add a Java Action in Oozie to run the java application created using JSch.
2. Use "/usr/bin/expect" library to create a shell script, which will perform ssh on edgenode and then run the configured shell script. More details are here Use expect in bash script to provide password to SSH command

Default user: WSO2 Identity Server with Mariadb

I followed the steps defined in this link and restarted the WSO2 identity server.
When trying to login at https://localhost:9443/carbon using admin/admin credentials, it's giving me login failed message. Before changing the settings for WSO2, it was working with this credentials.
Obviously, that user is not present in MariaDB. Does anyone has any scripts to insert an admin user in WSO2 Maria DB for? I don't know what all tables I need to update in case of adding user manually. Or is there any other default user?
Kindly suggest.
Had the same problem, even switched to mysql community and it didn't fix it.
So with mysql installed I did the following, after MANY tries,
mysql -u root -p
create DATABASE regdb;
exit;
mysql -u root -p regdb < <WSO2_HOME>/dbscripts/mysql5.7.sql
mysql -u root -p regdb < <WSO2_HOME>/dbscripts/identity/mysql-5.7.sql
nohup <WSO2_HOME>/bin/wso2server.h -Dsetup &
If there is someplace to see the DB version, I haven't found it, but this got it all to working form me. So loading keep failing the DB because of some default time functions in the sql.
My $0.02

Checklist When IBM WebSphere Application server is running up

I have an IBM WebSphere Application Server v8.5 (WAS) installed on Linux RedHat 6.
My question: how can I check on the following by command (if exist):
Is the application server running or not?
Is the web application that deployed on it running or not?
The database connectivity (using datasource) is connected successfully or not?
The easiest and quickest to check all these things is to use web administrative console available at http://yourHost:9060/ibm/console.
If you want to use command, then:
Is the application server running or not?
You can check that issuing serverStatus command (will check all servers):
%PROFILE_ROOT%/bin/serverStatus.sh -all
or for specific server:
%PROFILE_ROOT%/bin/serverStatus.sh serverName
the output will be something like:
C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\bin>serverstatus server1
ADMU0116I: Tool information is being logged in file
C:\IBM\WebSphere\AppServer85\profiles\AppSrv02\logs\server1\serverSta
tus.log
ADMU0128I: Starting tool with the AppSrv02 profile
ADMU0500I: Retrieving server status for server1
ADMU0508I: The Application Server "server1" is STARTED
Is the web application that deployed on it running or not?
There is no direct command for this. You can use wsadmin script for that. A simple one could be like the one below, if it returns entry the application is running:
print AdminControl.completeObjectName('type=Application,name=myApplication,*')
For more details check this question How do I determine if an application is running using wsadmin?
The database connectivity (using datasource) is connected successfully or not?
There is no direct command for this. You can use wsadmin script for that also. Here is sample script:
ds = AdminConfig.getid('/DataSource:Default Datasource/')
AdminControl.testConnection(ds)
For more details check this page Testing data source connections using wsadmin scripting
The serverStatus.sh command is s..l..o..w.. If you want an answer today then there is a file in the logs folder with the process PID:
/opt/IBM/WebSphere/AppServer/profiles/AppSrv01/logs/servername/servername.pid
That file contains the PID of the server process. If it is running:
ps -p pid
Then the server is up.
1. ps -ef | grep dmgr
2. ps -ef | grep <application name>
Also grep SystemOut.log for e-business and verify latest timestamp.
Log into admin console, browse to DataSource, display from all scopes, select your datasource and then click test. As long as the nodeagent is running and has been restarted at least once since the Datasource config and credentials were added, then this test should be fairly accurate.

Resources