Apache Server File Query - apache

I have an Apache server that has multiple files located on it. Each file is an updated version from the previous file. Eg. release-2013-07-20 is an older file and release-2013-07-25 is the newer file.
I am looking to query the apache server and have an display of the most updated file via website link.
I am unsure how to go about accomplishing this and I am looking for some suggestions.

If you're running on a unix server, the following command on the relevant directory will return the name of the file that was last modified (most updated):
ls -ltr | grep ^- | awk '{print $9}' | sed -n 1p
you can use this filename in order to copy or generate a link to it

Related

COPY FROM .csv file to a remote PostgreSQL Database (Running in Linux Server)

I'm trying to import data from .csv file to a PostgreSQL database hosted in a Linux Server, using the following command:
COPY areas_brasil FROM 'C:/Temp/RELATORIO_DTB_BRASIL_MUNICIPIO.csv' with delimiter '|' null 'NULL';
But i'm receiving the following error:
ERROR: could not open file
"C:/Temp/RELATORIO_DTB_BRASIL_MUNICIPIO.csv" for reading: No such file
or directory TIP: COPY FROM instructs the PostgreSQL server process
to read a file. You may want a client-side facility such as psql's
\copy.
The .csv file is in a client computer (running on Windows 10) in which i have administrator access to the database hosted in the server (running on Linux - Debian).
Thanks for helping me!
Welcome to SO.
COPY .. FROM 'path' assumes that the file is located in the server. If you wish execute COPY without having the file into the database server, you can either use \copy or just use the STDIN of psql from your client console, e.g. in unix systems (you have to find the cat and | equivalent for Windows):
$ cat file.csv | psql yourdb -c "COPY areas_brasil FROM STDIN DELIMITER '|';"
Using \COPY inside of psql it can be done like this:
\COPY areas_brasil FROM '/home/jones/file.csv' DELIMITER '|';
See this answer for more details.

Rename multiple files in SSH

I have a Centos server.
In SSH, I downloaded multiple mp4 files in a txt with this command:
wget -i urls.txt
Now I have a list of mp4 files in a directory. The problem is those mp4 files are named:
65464.mp4?md5=sdokj7SRuM-OKatFmdCJJg&expires=1570102642
45421.mp4?md5=sdokj56SRuM-OKatFmdCJJg&expires=157010277842
etc...
How do I remove ? and everything after in all files in this directory ( For example ?md5=sdokj7SRuM-OKatFmdCJJg&expires=1570102642 ) so it would change files name to:
65464.mp4
45421.mp4
etc...
Thank you.
The solution will depend upon what shell your CentOS system is running or has available. If you're running bash, you can do something as simple as:
for x in * ; do
mv $x ${x%%\?*}
done
This uses bash string variable manipulation techniques.
Another possible solution, still dependent upon shell features:
for x in * ; do
mv $x $(echo $x | sed "s/\?.*//")
done

Tail command - follow by name on Solaris

Is there a way to tail a file by name on Solaris 10?
Equivalent to:
tail --follow=name
Manual for tail on solaris shows no such option. Only -f is included and it looks like it follows a file by descriptor.
According to the GNU tail manual, --follows is the same as -f:
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
A -f option is found in the POSIX description of tail. However, the --follows option (which accepts an option value) is not in POSIX. The GNU manual goes on to describe the --follow option where it differs from -f:
With --follow (-f), tail defaults to following the file descriptor,
which means that even if a tail'ed file is renamed, tail will
continue to track its end. This default behavior is not desirable
when you really want to track the actual name of the file, not the
file descriptor (e.g., log rotation). Use --follow=name in that
case. That causes tail to track the named file in a way that
accommodates renaming, removal and creation.
That is, --follow provides for reopening the file if the actual file was renamed. POSIX does not appear to address this use case.
There is no direct equivalent in Solaris's differences from POSIX (compare /usr/bin/tail and /usr/xpg4/bin/tail in manual).
GNU tail is part of the coreutils package. You may already have it installed on Solaris 10, in /opt/sfw/bin/tail. For instance, pkginfo shows it on my Solaris 10 machine as SFWcoreu.
Solaris does not have --follow as you see.
The workaround is redirection:
tail -f inputfile > filewritten_by_tail
Your best bet is to install GNU find either from source or some freeware repository.
If you really want to stick with Solaris 10 bundled find, you'll need to wrap it with a custom monitoring program that will restart it should the target file is renewed.
Works like a charm on solaris 11!
/usr/bin/gtail -F

Running the WLST interpreter silently

I am trying to figure out a way to make the weblogic WLST terminal run in silent mode.
When i start the terminal with the java weblogic.WLST command, it prints the lines:
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
Is there a command line flag or some unknown witchcraft to make the interpreter not write these lines?
I wishfully tried -s for silent, to no avail.
And all my googling lead me to an -i flag that does something completely different.
EDIT:
To clarify my purpose:
I need the interpreter to run a python script, and i do need the output from that. The welcome message is useless clutter however, that i would like to be rid of.
Limited to:
The only problem i have is the first lines written by the interpreter itself. Once inside the python script i have no problem handling what send to the output. My only problem is the welcome lines written above. These are written by the interpreter itself, and not the python code.
To solve the problem, I did something little differente..
I put a grep -v in the output .. like this:
java weblogic.WLST script.py $ARGS | grep -v "Initializing WebLogic
Scripting Tool (WLST) ..." | grep -v "Welcome to WebLogic Server
Administration Scripting Shell" | grep -v "Type help() for help on
available commands" | grep -v "Successfully connected to Admin Server
\"AdminServer\" that belongs to domain \"domain\"." | grep -v
"Warning: An insecure protocol was used to connect to the server." |
grep -v "To ensure on-the-wire security, the SSL port or Admin port
should be used instead." | grep -v "Location changed to domainRuntime
tree. This is a read-only tree" | grep -v "with DomainMBean as the
root MBean." | grep -v "For more help, use help('domainRuntime')" |
grep -v "Successfully connected to Admin Server" | grep -v "Connecting
to t3://"
Try this:
Like you said "it's a hack", but it's a fairly elegant hack.
Create the file runwlst.sh:
#!/bin/bash
. ${WLS_HOME}/server/bin/setWLSEnv.sh >/dev/null 2>&1
FILENAME=$1
shift
java weblogic.WLST ${FILENAME} "$#" | sed -e "1,7 d"
WLS_HOME needs to be set, or use the absolute path to setWLSEnv.sh.
Then create your WLST scripts as "shell" scripts like so (I like to use the ".wlsh" extension for my scripts):
#!/bin/bash /absolute_path_to_runwlst.sh/runwlst.sh
# your WLST Python code starts here
import ...
This obviously the sed script used in runwlst.sh only works if the "Initializing" banner is 7 lines long, which could change with new releases or patches of WLS.
The benefit of this solution is that now you can just run your WLST scripts from the command line like so:
$ createManagedServer.wlsh domain servername
Or use WLST scripts is other shell scipts like so:
#!/bin/bash
PORT=`./getPortForManagedServer.wlsh domain server`
echo ${PORT}
you get the picture
I wanted for it to only show me lines that I print inside the script, so I did it simple - prepended special char sequence to all lines I wanted to see in logs (it was print('--> ...') in my case) and launched it like that:
wlst.sh changePassword.wlst.py "$#" | grep -- "-->"
Sample output:
Executing WLST script for domain SampleDomain
--> Executing credential change for SampleDomain
--> Changing DB password for DSTYPE1
--> Changing password for DataSource SampleDS1
--> Successfully changed DB credentials!
--> Changing password for DataSource SampleDS2
--> No JDBC resource with name SampleDS2 found, skipping...
--> Changing password for DataSource SampleDS3
--> No JDBC resource with name SampleDS3 found, skipping...
--> Changing password for DataSource SampleDS4
--> Successfully changed DB credentials!
Completed execution for domain SampleDomain
Bit of a long shot but you could also silence the entire JVM output by capturing stdout and stderr into a different stream and then print values captured from the weblogic mbeans to the console streams. I had to do something similar a while back after writing an ansible module which required me to return pure JSON to stdout without any message banners or other stuff printed to the terminal.
A possible solution for your needs would involve writing a python script that first changes the OutputStreams as in this example and then starts a WSLT session. Just remember to keep a "copy" of the console out streams and use these to write your results to.

Running grep on conf.xml widget definitions

I'm looking for pages defined by the ToolTwist Designer that use a specific widget. I've tried using grep to search for the widget name but nothing is found, even though I've checked it is in the file.
This is the command I'm using to check a specific page definition:
grep myproject.TestWidget widgets/test_pages/testPage/scratch_me/conf.xml
Any ideas what I'm doing wrong?
The widget definition files are stored as UTF-16 (but my change in the future). Before running grep, convert the file like this:
iconv -f UTF-16 -t ISO-8859-15 widgets/test_pages/testPage/scratch_me/conf.xml \
| grep myproject.TestWidget