I have this .rb file with the command:
cd /users/someusername/documents
The problem is that instead of "someusername", i would like to get the actual username of my target pc(which is my own pc used for penetration testing).
Update:
Just to clarify: I am running the resource script using the :resource: command from my meterpreter session. I guess this is different from running meterpreter scripts since the way I am doing it, runs every line in the file as a meterpreter command.
Any idea of how I could get the target's username from the file then? I mean the ENV does not seem to work with this approach. I am open for all suggestions!
Thanks! Much appreciated!
Direct shortcut (if available)
If someusername is the current user name, you could use :
cd ~/documents
Environment variable (if available)
current_user = ENV['USER']
cmd = "cd /users/#{current_user}/documents"
Getting username with id
This command could help you :
current_user = %x(id -un).chomp
cmd = "cd /users/#{current_user}/documents"
Yet another try
According to this post, resource files seem to be ERB files.
So you could write :
cd /users/<%= ENV['USER'] %>/documents
# or
cd /users/<%= %x(id -un).chomp %>/documents
Related
I'm running a command line script on multiple PC's and i'm trying to save username as a file name so i can see who's information i'm viewing later on.
In the command line script i run Whoami and i'd like to save it as "user"."file type". I'm trying to do this in a command line script because I always do it manually in command line and am trying to automate this process so I can do it faster.
If you know how to do it in a better way do share.
whoami > test.txt
tells it to go to a file and "test.txt" will be generated wherever your CMD CurDir is.
You may use Windows Environment variables %USERNAME% and possibly %USERDOMAIN% if the domain is needed.
%USERNAME% does not return the domain by itself.
Full list of standard environment variables: How-to: Windows Environment Variables
Use these in the command as needed. For example:
dir > %USERNAME%.txt
If you need the domain in there:
dir > %USERDOMAIN%_%USERNAME%.txt
(using _ to separate domain and username instead of \ since filename cannot contain \)
Remember to use >> instead of > if you don't want the file to be overwritten each time the command is run.
You may want to direct errors and standard output as needed: Redirecting error messages from Command Prompt: STDERR/STDOUT
I am getting error when calling OS command for Peoplecode using EXEC function.
The call is like this
CommitWork();
&ShellCommand = "/path/mytest.sh param1 param2";
&ReturnCode = Exec(&ShellCommand, %Exec_Synchronous + %FilePath_Absolute);
The &ShellCommand is built using the path, executable and parameters
to be passed as shown above. That command works fine when executed
independently.
I keep getting error 255. Is there anything about the syntax? Does anybody have a tested or working example or any suggestion?
Thank you guys for responding. The command was running fine from shell scripts but not from Peoplesoft. It turned out that the current folder on the application server was not correct. So I added a CD command as the first line in the shell script to change current folder to the correct folder. That worked.
Thanks again.
the syntax looks correct.
I use similar code to call bat files.
Exec("C:\windows\system32\cmd.exe /c C:\Test\mybat.bat param1 param2", %Exec_Synchronous+%FilePath_Absolute);
Have you tried with an absolute path instead of a relative path?
error code 255 seems to be an out of range error code.
see http://tldp.org/LDP/abs/html/exitcodes.html
I would check the assumptions that you're making.
Is the same username running the shell script, your username vs the app server username?
Is the environment set up the same way for the app server username vs your username?
file permissions
Hi can anyone help me out ?
I have just gotten a new laptop for developing and i have come to a halt already(7 mins).
When accessing files via the command prompt i keep getting this error "The directory name is invalid."
My file is saved on the desktop , i can navigate there well and good its just i cant enter into my eggs file or any file on my desktop via the command prompt. The path is correct.
C:\Users\toshiba\Desktop> cd ChromeSetup.exe
The directory name is invalid.
I have messed around with the command prompt settings and that but to no avail :/. If someone could help me out id be so grateful as i have to start an important project and have been stuck on this for a while now. Thanks in advance.
You can CD to folders, not to files.
This is because CD is short for:
Change Directory
cd ..\..\toshiba\Desktop should work, because you CD in your folders
running cd ChromeSetup.exe is never going to work, unless ChromeSetup.exe is some weird folder name.
If you want to execute that executable without closing the CMD prompt, run this command:
cmd /K "ChromeSetup.exe"
If you want to open a file with a chosen program, use the executable command and give the filename as parameter:
"C:\Program Files\Adobe\Photoshop\photoshop" "C:\Users\user\Documents\document.pdf"
I want to run a bash script on a mac remotely from a batch script on a windows machine. On Windows I have this:
#echo off
echo bash /applications/snowflake/table-updater/test2.sh; exit>tmp_file
putty -ssh User#remote_machine -pw password -m tmp_file
And here is test2.sh on the remote machine
#!/bin/bash
# test2.sh
#
#
7za x table-apps.zip -y -o/Applications/snowflake/applications
When the batch file runs it logs in successfully, but for some reason fails to run the bash file. However the bash file runs fine from mac terminal, where it unzips the files perfectly. What could be happening here?
Please note test2.sh is actually in Applications/snowflake/table-updater as specified in the batch file. And the tmp file does write fine as well. My aim is to have a script to access a further 10 remote machines with the same directory structure.
Thanks in advance
The standard program which resembles the scriptable Unix command ssh in the PuTTy suite is called plink, and would probably be the recommended tool here. The putty program adds a substantial terminal emulation layer which is unnecessary for noninteractive scripting (drawing of terminal windows, managing their layout, cursor addressing, fonts, etc) and it lacks the simple feature to specify a command directly as an argument.
plink user#remote_machine -pw password /Applications/snowflake/table-updater/test2.sh
From your comments, it appears that the problem is actually in your script, not in how you are connecting. If you get 7za: command not found your script is being executed successfully, but fails because of a PATH problem.
At the prompt, any command you execute will receive a copy of your interactive environment. A self-sufficient script should take care to set up the environment for itself if it needs resources from non-standard locations. In your case, I would add the following before the 7za invocation:
PATH=$PATH:/Applications/snowflake/table-updater
which augments the standard PATH with the location where you apparently have 7za installed. (Any standard installation will take precedence, because we are adding the nonstandard directory at the end of the PATH -- add in front if you want the opposite behavior.)
In the general case, if there are other settings in your interactive .bashrc (or similar shell startup file) which needs to be set up in order for the script to work, the script needs to set this up one way or another. For troubleshooting, a quick and dirty fix is to add . /Users/you/.bashrc at the top of the script (where /Users/you should obviously be replaced with the real path to your home directory); but for proper operation, the script itself should contain the code it needs, and mustn't depend on an individual user's personal settings file (which could change without notice anyway).
How does one change the current directory in SQL Plus under windows.
I am trying to write a script with several "# filename" commands.
I know that one can open a script with the File --> Open command, which will change the current directory, but I am looking for a way to do this automatically unattended.
Resolution
Based on Plasmer's response, I set the SQLPATH environment variable in Windows, and got something that's good enough for me. I did not try to set it with the HOST command (I doubt that it will work).
Pourquoi Litytestdata's answer is a good one, but will not work for me (the directories are too far apart). And of course Guy's answer that it cannot be done is also correct. I will vote these two up, and accept Plasmer's answer.
Here is what I do.
Define a variable to help you out:
define dir=C:\MySYSTEM\PTR190\Tests\Test1
#&dir\myTest1.sql
You can't cd in SQL*Plus (you can cd using the host command, but since it is a child process, the setting won't persist in your parent process).
I don't think that you can change the directory in SQL*Plus.
Instead of changing directory, you can use ##filename, which reads in another script whose location is relative to the directory the current script is running in. For example, if you have two scripts
C:\Foo\Bar\script1.sql
C:\Foo\Bar\Baz\script2.sql
then script1.sql can run script2.sql if it contains the line
##Baz\script2.sql
See this for more info about ##.
Could you use the SQLPATH environment variable to tell sqlplus where to look for the scripts you are trying to run? I believe you could use HOST to set SQLPATH in the script too.
There could potentially be problems if two scripts have the same name and both directories are in the SQLPATH.
I don't think you can!
/home/export/user1 $ sqlplus /
> #script1.sql
> HOST CD /home/export/user2
> #script2.sql
script2.sql has to be in /home/export/user1.
You either use the full path, or exit the script and start sqlplus again from the right directory.
#!/bin/bash
oraenv .
cd /home/export/user1
sqlplus / #script1.sql
cd /home/export/user2
sqlplus / #script2.sql
(something like that - doing this from memory!)
With Oracle's new SQLcl there is a cd command now and accompanying pwd.
SQLcl can be downloaded here: http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html
Here's a quick example:
SQL>pwd
/Users/klrice/
NOT_SAFE>!ls *.sql
db_awr.sql emp.sql img.sql jeff.sql orclcode.sql test.sql
db_info.sql fn.sql iot.sql login.sql rmoug.sql
SQL>cd sql
SQL>!ls *.sql
003.sql demo_worksheet_name.sql poll_so_stats.sql
1.sql dual.sql print_updates.sql
SQL>
Have you tried creating a windows shortcut for sql plus and set the working directory?
I think that the SQLPATH environment variable is the best way for this - if you have multiple paths, enter them separated by semi-colons (;). Keep in mind that if there are script files named the same in among the directories, the first one encountered (by order the paths are entered) will be executed, the second one will be ignored.
Years later i had the same problem. My solution is the creation of a temporary batchfile and another instance of sqlplus:
In first SQL-Script:
:
set echo off
spool sqlsub_tmp.bat
prompt cd /D D:\some\dir
prompt sqlplus user/passwd#tnsname #second_script.sql
spool off
host sqlsub_tmp.bat
host del sqlsub_tmp.bat
:
Note that "second_script.sql" needs an "exit" statement at end if you want to return to the first one..
for me shelling-out does the job because it gives you possibility to run [a|any] command on the shell:
http://www.dba-oracle.com/t_display_current_directory_sqlplus.htm
in short see the current directory:
!pwd
change it
!cd /path/you/want