Friday, July 8, 2022

Oracle fun without dba privileges

A selection of information you can find on Oracle without special privileges. * Oracle version select * from v$version; * Password expiration date for this user select username,expiry_date from user_users; * Number of rows in this user's tables select table_name,num_rows from all_tables where owner = 'THISUSER' order by table_name; * Possession of the DBMS_LOB role Some critical info DOES require special privileges, including * User session limit * Maximum processes per SID And I'm not sure about * Storage utilization by this user * Storage utilization by this SID * Grants to this user from neighboring users

Wednesday, November 10, 2021

How to download Elastic plugins

 There's no searchable answer for this, so I hope mine finds its way into an index somewhere.

How do you download Elasticsearch plugins?
How do you download Elastic plugins directly?
How download Elastic plugin proxy?
Where Elastic plugin repo argh?

Simple answer:  There's a download link on each plugin page.  

For example, there's a link to the current artifact in the middle of the Analysis-SmartCN page. which is listed on the Plugins and Integrations page.

It's obnoxious.  It's the last place you'd look if you're not handcrafting this stuff.  But at least now you can stop using elasticsearch-plugin to download these things into a dummy instance.

Here are the four plugins you need to use ES 7.15 with Liferay 7.2 or 7.3.

To install, use the file:// parameter, e.g., 

elasticsearch-plugin install file:///path/to/zip


Monday, August 23, 2021

Not Unixish: Scanning with the Canon MF4770n and OS 10.14

I just had a rather infuriating half-hour.  Here's how to enable network scanning from MacOS 10.14 to a Canon MF4770n printer.

First, disregard the official Canon documentation. Disregard it as hard as you can.

  1. Go to the device's download page.
  2. The download page may autodetect "Mac OS X" and say no files are available.  Select MacOS 10.14 instead.  There are two; pick the one with more files under it.
  3. Download and install the scan utility, currently mac-scan-2158.dmg .  It includes the driver and some utilities.
  4. Take a moment to visit the printer and make sure the benighted thing has a valid IP.
  5. Open System Preferences -> Printers.  Add the printer, hopefully via Bonjour.  This isn't Windows, so Autodetect will find the driver.
  6. In System Preferences -> Printers, the MF4770n has Print and Scan tabs above its picture.  Select Scan.
  7. On the printer, lay out your document and click the Scan button.  Then choose "Remote Scanner".  The Send-To option is tempting, but doesn't work for me.
  8. Back in System Preferences, click "Open Scanner".  The scanner will automatically do an overview. By default, it'll attempt to identify separate items. 
  9. Once the overview is complete, press Scan. If you disabled Auto Selection, you'll be required to select an area.  By default, images go to the Pictures folder.  

If you receive error code 2100010, it probably means the scanner isn't listening in Remote Scanner mode.

If the scanner doesn't show up after adding the printer in SysPref, MF Toolbox may help.

  1. Open MF Toolbox, which was installed by the driver dmg.  Ignore any warnings about not finding a scanner.
  2. Under MF Toolbox -> Network Scanner settings, add the printer.  Hopefully it shows up over Bonjour; I haven't tried IP. 
  3. Close MF Toolbox; you're done with it.
  4. Scan using SysPref as described above.

H/T to Darius in the Canon forum for showing that the official docs are wrong, and Nidhish on FixYa for demystifying the printer menu.

Monday, August 13, 2018

Bottle shaking: Reset Mac's SMC and PRAM

I just requested help with symDaemon abusing my Mactop's CPU at random and fan noise embarrassing me at meetings. I was advised to reset my SMC and PRAM.

On the off chance it works, these are the dance steps.
  • SMCShut down.  Hold ctrl-option-power.  Watch for the power adapter to flash green.  (Obvs, it helps if the charge LED is orange when you start.  If it's green, I guess it still flashes.
    The machine remains powered down.
  • PRAM  While shut down, hold -option-p-r-power.   When it starts to come up, let go of the power button. 
    Continue holding the other buttons through three reset cycles, marked by the default startup sound. 
    After the third startup sound, let go of the buttons and allow the machine to start up as usual.
The SMC relates to hardware.  It probably won't do anything for my antivirus woes, but might help my dumb machine correctly recognize its lid position. (Apple: How to reset the SMC)

The PRAM is less clear.  It stores startup settings, so ... maybe?  But I haven't seen anything where Symantec admits to storing stuff there.  (Apple: Reset NVRAM or PRAM on your Mac)

Thursday, December 21, 2017

A much easier way to ream out an Oracle schema

This self-concatenating method is much better than the shell-based solution I wrote about a few years ago.

set heading off
set pagesize 0
select 'drop '||object_type||' '|| object_name|| DECODE(OBJECT_TYPE,'TABLE',' CASCADE CONSTRAINTS','') || ';'  from user_objects;
Execute the output, then

purge recyclebin;
select * from user_objects
Very satisfying.  Much less fiddly.

Thursday, January 26, 2017

No, you can't edit Font Book collections

After vigorous searching for "how to delete a font from a group in fontbook" and "how to remove a font from a collection in Font Book" and such, I've concluded that there is no such feature.

These are not the options you're looking for.  Move along.
Did you misfile a useless symbol font in your "Stencils" folder?  Well, valued Mac user, you'll just have to deal with the consequences of your actions.  Apparently you used to be able to drag the offending font onto the desktop and letting it go poof.  However, that's definitely not working for me on 10.11 El Cap.

There's a simple workaround:  The collections themselves can be deleted.  Rename the contaminated collection and create an empty one with the desired name.  Move all the stuff you actually want into the new collection, then delete the renamed contaminated collection via the File menu.

I fully acknowledge that this is going to be useful to precisely nobody I know. Maybe Hugh.  I'm just posting it in the vain hope that it will short-circuit the next person's fruitless search for a nonexisting feature.


Friday, November 25, 2016

Editing cells in SQL Developer

I rarely edit my databases directly, and of those rare edits, I'd say that less than 1% are done to individual cells.  Usually, it's because I need to twiddle a knob that Liferay has buried in an XML CLOB. So when I do need an editable grid, I can only remember how to get to it by browsing, which is incredibly tedious.

But there's a better way!

  1. Find the offending cell using the query worksheet, then copy the WHERE clause.
  2. In the query, hold down ⌘ (Ctrl on Windows) while mouse hovering over the table name.  The table name becomes a link.

  3. Click on that link.  (Once you know about this behavior, you can ⌘-click without hovering.)
  4. Now you're in the data grid for the selected table.  Paste the WHERE clause from your buffer and hit Enter.

  5. Double click on any record to edit it, or right-click on the row to use Single Record View.
  6. YOU WIN.  EVERYBODY WINS.

For the sake of completeness, here's the tedious way:

  1. In the connections browser, expand the schema.
  2. Expand Tables.
  3. Scroll, scroll, scroll down to the desired table.  Wait, you missed it.  Scroll back up.
  4. Click on the table name.  This opens the data grid, as in step 4 above.

h/t That Jeff Smith

Monday, March 2, 2015

Check when your password will expire

I hate to even admit it, but there are still some places where my password is managed locally.  (Ugh.  Maybe I should have put a trigger warning on this post.)  Anyway, this means that it's occasionally useful to know when I last changed my password and/or when I will need to do it again.

It turns out that chage, which I had thought was really only useful for root, provides a way for non-root users to check their own accounts.

somesrvr kexline@somesrvr ~
$chage -l kexline
Last password change     : Mar 02, 2015
Password expires     : Mar 06, 2015
Password inactive     : never
Account expires     : never
Minimum number of days between password change     : 0
Maximum number of days between password change     : 4
Number of days of warning before password expires   : 2

Friday, July 11, 2014

Oracle password expiry without DBA privs

Here's how to get password expiration information without DBA privileges.

SQL> select * from user_password_limits;

RESOURCE_NAME LIMIT
-------------------------------- ----------------------------------------
FAILED_LOGIN_ATTEMPTS 10
PASSWORD_LIFE_TIME 180
PASSWORD_REUSE_TIME UNLIMITED
PASSWORD_REUSE_MAX UNLIMITED
PASSWORD_VERIFY_FUNCTION NULL
PASSWORD_LOCK_TIME 1
PASSWORD_GRACE_TIME 7

7 rows selected.

SQL> select account_status,expiry_date from user_users;

ACCOUNT_STATUS EXPIRY_DA
-------------------------------- ---------
OPEN 03-JAN-15

At some point, I need to collect all my DBA-free Oraclejitsu into a single document.  But I say the same thing to that that I say to death:  "Not today."

Wednesday, April 2, 2014

Shell one-liner: Get your effective Ghostscript path

I amuse me.


gs -? | grep \/ | grep : | sed 's/\ //g' |  sed 's/:/\n/g' | grep -v ^$ | xargs ls -ld 2>&1 |  grep -v "No such" | awk '{print $NF}' | tr '\n' ':'

Ghostscript's helpfile mentions its font path.  However, it's not presented in a usable format, and worse, it includes directories that don't exist.  This cleans it up and spits it back out in a format that you can paste into a path configuration.

Saturday, March 29, 2014

Destroy a schema from the inside

Oracle does not provide a way for a user to pave over his own schema.  If you don't have dba privileges, this means you have to remove your schema by destroying each object.

This is a VERY rough recipe that I just wrote for a coworker.  It assumes you have Oracle SQLDeveloper and a shell handy.
  1. sql> select /*csv*/ 'DROP ',user_objects.object_type,' ',user_objects.object_name from user_objects where object_type in ('INDEX','TABLE');
  2. F5 (run as script)
  3. Select everything in your output window and copy it to /tmp/objects
  4. bash> cat /tmp/objects | grep -v OBJECT_NAME | sed s/\"//g | sed s/\,//g | sed s/$/\;/ > /tmp/drop.sql
  5. In SQLNavigator, clear your query and output screens (pencil eraser)
  6. File -> Open /tmp/drop.sql
  7. F5 (run as script) -- drops may cascade, which will cause errors later in the script; ignore
  8. sql> purge recyclebin;
  9. sql> select * from user_objects;  -- should return 0 rows now.
This can easily be adapted to whatever Oracle client and text editor you have handy.  In place of the seds and greps, use a basic text editor to remove the header line, remove all commas and quotes, and add a semicolon to each line.




Thursday, January 30, 2014

Awk: Print all but the last field

The other day I had a list of files, and needed to extract a list of the directories containing those files. So, in more general terms, I needed everything but the last field of each line.   That can be done in awk with

awk -F/ '{$NF=""; print $0}' filename 

i.e., you set the Nth field to null, then print the modified item.   You can do that with other fields as well -- $1, $(NF-1), and so on.

But that changes all the slashes to spaces. I knew there were no spaces in my list, so I fixed it with sed:

awk -F/ '{$NF=""; print $0}' filename | sed s/\ /\//g 

I could also have used the OFS (output field separator) directive in awk, but that doesn't work within a one-liner.

awk -F/ 'BEGIN { OFS = "/"}{ $NF=""; print $0 }' filename 

You can also edit the output record separator the same way -- for example, if you're sedawking a batch script, perhaps you want to add semicolons.

awk -F/ 'BEGIN { OFS = "/"; ORS=";\n"}{ $NF=""; print $0 }' filename 

 (h/t One Tip Per Day and GNU)

Thursday, August 8, 2013

Newbie help: Finding yourself (assuming you're a script)

Sometimes a script needs to figure out its own filename.  This is useful when creating error output and logs -- basically, anytime that the source of a chunk of output might be ambiguous.  This is done via basename:

myname = `basename $0`

Why basename $0?  If you think about handling arguments in shell scripts, you'll recall that the first argument is $1, the second is $2, and so on.  So the full pathname of the script is the zeroth argument.  Basename simply strips that string down to the filename.

To do the same thing, but get the containing directory instead, use

mydir = `dirname $0`

Easy enough.

Unfortunately, $0 only gives you the path of the script as it was run.  So if we do this:

cd /opt/somedir
./subdir/script.sh

then dirname $0 will only return ./subdir .  That's not useful if we need to change directories during the course of script.sh without losing track of where we started.

Here's the solution:

SCRIPTPATH=$( cd "$(dirname "$0")" ; pwd -P )

Spawn a subshell, cd into the directory using the relative or absolute path from dirname $0, and then print the working directory of the subshell.  This version resolves symlinks; omit the -P to preserve them.

(This post is mostly an excuse to write that last trick down.  Thanks to the folks on this post for coming up with it.)

Wednesday, May 8, 2013

Newbie help: find basics

The find command is a general file-finding utility with much a much broader range of talents than locate.  Find starts from a given directory and locates all files below that directory that meet specified constraints.  You can look for files by name (or regex), size, age, ownership, permissions, or any combination.

Find has built-in actions, such as delete, ls, print[ to file], and exec[ute-another-command].  You can also pipe the output into other commands.  I'll cover actions in a later post.

Basic syntax:
find path -constraint value

Add as many constraints as you like.   Any flag can be negated with a bang; see the very last examples for the syntax.

The most common constraints are size, and modified date (-mtime).  Both of these flags can serve as an upper or lower bound.

Example:  Which files below the current directory are less than five days old and more than 5kb?  Which are more than five days old and less than 5kb?

find . -mtime -5 -size +5000
find . -mtime +5 -size -5000

The -type flag allows you to specify whether you're looking for files or directories.  By default, find returns both.  Depending on your OS, the values will be either "f" or "file", and either "d" or "dir".  Check man for details.

The -name flag can take a full case sensitive filename, or a regex pattern.  If you use a pattern, enclose it in double quotes.

find /app -name applog
find /app -name "*log"
find . -name "*dunno*"
find . -name "[j,J]ava*"

Find can also identify files owned by a specific user or group.  (This flag is available on OS X, but doesn't appear to work.)

find /tmp -user kexline

Combine flags to ask real-world questions about your files.  Example:  What largish, non-gzipped  files did I create in my application directory since this time yesterday?

find /app -type f -mtime -1 -user kexline -size +100000 ! -name "*gz"

As promised, there's a bang negation.  Any flag can be prepended with a bang to reverse its meaning.  What files did all the other non-root users create yesterday, anywhere on the machine?

sudo su 
find / -type f -mtime -1 ! -user kexline ! -user root 

Newbie help: The "locate" command

Some *nixes, including Centos and Red Hat have an indexed finder utility called locate.  It's a very limited tool, but when you know what you're looking for, it can be the quickest way to find a file.

Basic usage:
locate [-i insensitive, -w wholename] a-filename-substring

It will generally return too much info, so grep for other known substrings to pare down the results.

Example:  I know exactly what file I want, but where did I put it?
$locate iCanHasPortlet.war
/app/liferay/iCanHasPortlet.war

Example:  I only know bits of a ridiculously long filename, what was it?
Mac:~ kexline$ locate -i license | grep -i prod | grep -i acme
/Users/kexline/Documents/liferay/licenses/license-production-production-5.6sp3-acmecomputercompany-main.xml

If locate doesn't cough up the goods, then your index is probably older than the desired file.  (Locate is not useful for new files; but then again, if something is very new you should know what or where it is.)  On RH/Centos, become root, run updatedb & , and get some coffee. 

Newbie help: Is this file in use?


You can use "fuser" to check whether any processes have a file open.

$ fuser somefile 
somefile:        20719
$ fuser anotherfile
$

Pid 20719 is using somefile, but nothing is using anotherfile.

Pipe queen bonus:  I want to compress some old stuff in a directory.  Here are some big files:
$du -sk ./* | sort -n | tail -5
71796 ./applog.20120418.gz
349252 ./applog
422952 ./applog.20120613
598672 ./applog.20120627
2816980 ./applog.20130204

Which of the largest five files are in use, if any?
$du -sk ./* | sort -n | tail -5 | awk '{print $2}' | xargs fuser
./applog:      44827

Pid 44827 is using the current applog.  The last three are safe to compress.

(Tangent:  Compression generally writes to the current filesystem.  Therefore, you can't compress in a filesystem that's 100% full.)

Newbie help: Why is my filesystem full?

If a filesystem fills up and you have no idea where to start, try the disk usage command. This will at least help you find breathing room, and it may help you find the overgrown or unexpected file that caused the problem.

If you haven't already, use df to make sure you know which filesystem is full.  Many systems only have one filesystem, but it's more common to have a few.  For the purpose of this discussion, you're only concerned about files below the mount point of one overutilized filesystem.


Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vgroot     30G  3.6G   25G  13% /
tmpfs                 1.9G  4.0K  1.9G   1% /dev/shm

/dev/mapper/vgapp      20G  6.7G   13G  96% /app

nfssrv:/vol/devshare   10G  192K   10G   1% /app/dshare
nfssrv:/export/home/fred
                      102G   90G   12G  89% /home/fred


cd to the mount point or a point in the directory tree where you suspect things might have gone awry, then do this:

du -sk ./* | sort -n 

In English, that's "disk usage -specific_file -kilobytes, then sort -numeric." These flags will be the same on any *nix.

Non-root users will receive a lot of "Permission denied" errors when running this command in system or shared directories. This can be a good thing; if you're interested in finding files created by a certain user, the errors show you where not to look. On the other hand, if you're really in the dark and/or troubleshooting a multiuser system, you may need to become root.

You can use du to identify the largest directories, which may help you find your problems. 

An example:

$cd /app
$ls -atlr
total 8167528
dr-xr-xr-x. 30 root   root      4096 Mar 20 03:51 ..
drwxr-xr-x.  7 lruser lrgrp     4096 Mar 26 20:04 common
drwxrwxr-x.  9 lruser lrgrp  1490944 Apr 23 16:24 .
drwxr-xr-x. 16 lruser lrgrp     4096 May  1 16:52 calendar
drwxr-xr-x. 14 lruser lrgrp     4096 May  7 18:16 liferay

Not much help, right?  But du makes it easy to decide where to look first.
$du -sk ./* | sort -n
644116 ./common
1563248 ./calendar
8613876 ./liferay

So the Liferay directory's pretty chubby.  Why is that?
$cd liferay
$du -sk ./* | sort -n
0 ./jdk-liferay
4 ./deploy
520884 ./data
1092408 ./logs
1232588 ./backup
5492700 ./appserver

Unsurprisingly, the JVM accounts for most of Liferay's 8gb.  I should also look for things to delete from the backup directory, but let's stick with the big fish for now.
$cd appserver
$du -sk ./* | sort -n
...
149408 ./temp
419056 ./web
4759364 ./logs

And again unsurprisingly, the logs directory accounts for most of the JVM's utilization.  Du works on files as well, so you could use it to quickly find the largest file in a directory.
$cd logs
$du -sk ./* | sort -n
54340 ./applog.20121001.gz
71796 ./applog.20120418.gz
349252 ./applog
422952 ./applog.20120613
2816980 ./applog.20130204

Wait, I'm lazy.  How big was that last file?
$ls -lh applog.20130204
-rw-r--r--. 1 lruser lrgrp 2.7G Feb  4 16:55 applog.20130204

Many commands that show file sizes, such as df,  du, and ls, have a -h (-human_readable) flag.  We use du -k because the -h output is not easily sortable.

If you haven't freed enough space or found your culprit, pick another place in the tree and du down from there.



Friday, September 18, 2009

How to enable kernel dumps on RH4

This was rather annoying to find, so for now, a pointer --
http://www.nocrack.fr/?p=24

Monday, June 22, 2009

Fixing X11 on Red Hat

Every time I upgrade the kernel on my Red Hat machine and reboot, startx errors out. The xorg.0.log says, "(EE) NVIDIA(0): Failed to load the NVIDIA kernel module!"

NVidia has tips here, but they are predicated on running modprobe nvidia. When I did that, modprobe and rmmod reported that the nvidia driver was not present in /proc/modules.

The fix for my machine:
  1. Run nvidia-installer --update
    • OR, Run nvidia-installer-latest to get the FTP URL for the latest nvidia driver.
    • Download same using wget. (Cut & paste may work.)

Tuesday, March 24, 2009

Extending a swap LVM in Redhat 4 or 5

This refers to a pre-production box. Note, before you start, that swapoff is involved, and consider whether you want to do that to a busy box. :)
  • lvscan
  • lvextend --size +4G /dev/someVG/someVol
  • lvscan
  • free -m
  • swapoff
  • mkswap /dev/someVG/someVol
  • swapon -va
  • free -m