ForgeRock Directory Server(OpenDj) ldapsearch in windows cmd ( not Linux) - ldap

If I want to search an LDAP entry from a LDAP server using ForgeRock Directory Server(OpenDJ), the document says in Linux it works like the following.
$ ldapsearch \
--hostname localhost \
--port 1389 \
--baseDn dc=example,dc=com \
"(cn=Abagail Abadines)" \
cn mail street l
If I want to run this command in Windows, it doesn't seem to work.
What do I need to change in this command to run it on Windows's cmd.

It works the same, you just need to use ldapsearch.bat, and use the Windows continuation character (^) instead of \, or put all arguments on a single line.
Also, when reading the documentation, the upper right corner icon allows you to copy the example command to your clipboard.

I figured it out after two hours of trying! I hope this might help someone. In Linux, \ means new line (of course, it also means escape sequence). It created new line. So in Window's cmd mode, just type the whole command without \
Also, even in Linux, typing the whole command without \ seem to work fine without any error. (By putting \ every line somehow didn't work in the middle. )
In Unix/Linux, Windows, and Mac, '/' (slash) and '\' ( backslash ) are confusing a little. So when executing commands or setting paths, gotta watch out.

Related

Run multiple commands using wsl

I have some scripts on my home folder that I would like to run from command line, actually from the task scheduler, but I don't find the way to do so.
I have tried
wsl -u Ubuntu -u jlanza "cd /home/jlanza/bin && ./myscript && ./myotherscript"
but it doesn't work.
How can I concatenate the execution of several commands under the same session?
You need to escape && so powershell does not see them as different commands, to pass && to wsl do the following:
wsl -d Ubuntu -u jlanza -- cd /home/jlanza/bin `&`& ./myscript `&`& ./myotherscript
You need to pass those commands to WSL without the quotes so that bash interprets them correctly as a series of commands chained together, rather than a single long command. Unfortunately, when you do that, the '&&' operator gets interpreted by the Windows command line interpreter and the commands following do not get passed to WSL.
What I've found to work is replacing the '&&' (run command only if the preceeding command exits with success) operator with simple ';' (run command regardless of how the preceeding command exited). In your case then, something like this should work:
cmd /c "wsl -u Ubuntu -u jlanza cd /home/jlanza/bin; ./myscript; ./myotherscript"
However, if your use cases neccesitates the use of the '&&' operator, I'd try saving the command you're running as a script or an shell alias in the WSL. Calling that would then save you the need of passing '&&' through the Windows command line interpreter.
C:\Windows\System32\wsl.exe -d Ubuntu -u jlanza sh -c ". ~/.profile && script-jlanza.sh"
This way I load my own own profile and then I'm able to run the commands.
The option is just to run sh or any shell and then execute the commands you'd like within that shell. The other answer is also valid, but I like mine most, as I'm able to use the user profile (path, aliases, etc.)

SSH - Grep with special chars and *

I'm looking to search some files via SSH with the grep command but I have some special chars.
The string I'm looking for is:
"$GLOBALS['....'];"
I tried this one
grep -r -H "\$GLOBALS\\['*'\\]\;" /var/www/
but nothing happens. Any help will be welcome.
Your RE actually matches "$GLOBALS['''''''];" with one or more ' there.
try this one:
grep -rHP "[$]GLOBALS\['.*?']\;" file
I use [$] instead of \$, is because ESCAPE IS SOMEHOW TRICKY, some environment you need use \\\$.
Update, less than 10 chars inside the []:
grep -rHP "[$]GLOBALS\['.{0,10}']\;" file

Makefile and use of $$

So I have a Makefile in which I have the follwoing code that I try to understand:
for file_exe in `find . -name "zip_exe-*"`; do \
./$${file_exe} -d $(UNZIP_PATH)/lib; \
done
As I understand this piece of code will try to find some executable zip and the extract those zip files to a locations. But what puzzles me is how $${file_exe} is working. Why is the double $$ needed? I guess it has something to do with the fact that some bash commands are running from a makefile, but I can't explain to myself why the $$ is needed and a simple $ does not work since this command is running a sub-shell anyway.
Make needs to distinguish whether you want a $ to use as introducing a make-variable reference, such as ${FOOBAR} or as a plain $ passed on to the shell. The make specification (Section Macros) says that to do the latter, you must use $$ which is replaced by a single $ and passed to the shell. In effect, your snippet reads as
for file_exe in `find . -name "zip_exe-*"`; do \
./${file_exe} -d some/unzip/path/lib; \
done
to the shell.
Style note: Iterating over file lists created by backticks is considered bad style, since it may overflow the ARG_MAX limit. Better to read the file names one-by-one with
find . -name "zip_exe-*" | \
while read -r file_exe; do \
./${file_exe} -d some/unzip/path/lib; \
done

Unable to run a postgresql script from bash

I am learning the shell language. I have creating a shell script whose function is to login into the DB and run a .sql file. Following are the contents of the script -
#!/bin/bash
set -x
echo "Login to postgres user for autoqa_rpt_production"
$DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT
echo "Running SQL Dump - auto_qa_db_sync"
\\i auto_qa_db_sync.sql
After running the above script, I get the following error
./autoqa_script.sh: 39: ./autoqa_script.sh: /i: not found
Following one article, I tried reversing the slash but it didn't worked.
I don't understand why this is happening. Because when I try manually running the sql file, it works properly. Can anyone help?
#!/bin/bash
set -x
echo "Login to postgres user for autoqa_rpt_production and run script"
$DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT -f auto_qa_db_sync.sql
The lines you put in a shell script are (moreless, let's say so for now) equivalent to what you would put right to the Bash prompt (the one ending with '$' or '#' if you're a root). When you execute a script (a list of commands), one command will be run after the previous terminates.
What you wanted to do is to run the client and issue a "\i ./autoqa_script.sh" comand in it.
What you did was to run the client, and after the client terminated, issue that command in Bash.
You should read about Bash pipelines - these are the way to run programs and input text inside them. Following your original idea to solving the problem, you'd write something like:
echo '\i auto_qa_db_sync.sql' | $DB_PATH -U $POSTGRESS_USER $Auto_rpt_production$TARGET_DB -p $TARGET_PORT
Hope that helps to understand.

Run commands in GNU Screen windows from .screenrc

Is there a way to send a sequence of commands to GNU Screen windows from my .screenrc? It seems like this should be easy to do:
.screenrc:
startup_message off
screen -t "RAILS SERVER"
<send command to last created window> <my alias to cd Rails project>
<send command to last created window> rails s
screen -t "RAILS CONSOLE"
<send command to last created window> <my alias to cd to Rails project>
rails c
I've gone over the Screen man-page several times, but can't find anything that will <send command to last created window>.
Thanks,
Max
Keith's answer gets the job done but it ties the window to that process so that as soon as the application is done executing, the window closes.
Here's what I wound up doing that worked perfectly:
screen -t "RAILS SERVER"
stuff "cd $my_rails_directory; rails server^M"
screen -t "RAILS CONSOLE"
stuff "cd $my_rails_directory; rails console^M"
The important part to note here is the ^M character. This isn't actually a ^ followed by an M. This is a raw newline character. In almost any CLI program (vi, emacs, shell), you can press CTRL-V and then press ENTER to generate this character.
How does this work? The stuff command types the given string directly into the console. The newline literal at the end actually sends the command off the way you normally would if you typed it yourself. Hope that helps! I've found this approach to be far more stable and reliable than others.
It's not a separate command; you just specify the command to run on the line that creates the window.
For example (untested):
screen -t "RAILS SERVER" sh -c "cd ... ; rails s"