how to use ionice with alias - alias

ionice does not seem to work with aliases. I am using zsh, I did not test bash. e.g.
$ alias foo='ls -l'
$ ionice -c2 -n2 foo
ionice: executing foo failed: No such file or directory
Why does ionice not recognice the alias and how can I get it to recognize the alias?

You need to use a global alias:
alias -g foo='ls -l'

Related

kubectl bash completion for alias with options

I have several kubectl aliases configured:
alias k='kubectl'
alias kn='kubectl -n'
alias ks='kubectl -n kube-system'
alias ka='kubectl get --all-namespaces'
Bash completion works fine for kubectl and I got it working for most of the aliases as well by calling
complete -o default -F __start_kubectl $alias
This does however not work for the ka alias - the completion ignores that the get is already part of the alias and completes the command as if it wasn't there.
Is it possible to configure the completion to also work for the ka alias?
OS is a docker container using Ubuntu 16:04 as base image.
When aliasing kubectl use = options
From https://github.com/kubernetes/website/issues/31824#issue-1146171318
Setting flags/options in your alias requires the = format
Hence aliases should be created as follows:
alias k='kubectl'
alias kn='kubectl --namespace='
alias ks='kubectl --namespace=kube-system'
alias ka='kubectl --all-namespaces get'
alias kp="kubectl --kubeconfig=~/.kube/production.kubeconfig --namespace=prod"
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"23",
GitVersion:"v1.23.5",
GitCommit:"c285e781331a3785a7f436042c65c5641ce8a9e9",
GitTreeState:"clean", BuildDate:"2022-03-16T15:58:47Z",
GoVersion:"go1.17.8", Compiler:"gc", Platform:"linux/amd64"}

Zsh over-substituting aliases

In Bash, running tmux ls works properly. However, in Zsh, I get this error:
tmux: unknown option -- p
usage: list-sessions [-F format]
I suspect this is because Zsh is replacing ls of the command with my custom alias for ls:
alias -g ls='ls -p --color'
I tried setting alias -g tmux\ ls='tmux list-sessions', but that didn't work.
Is there any way to change Zsh's alias expansion/substitution behavior?
You are defining ls as a global alias, meaning it is expanded anywhere the shell sees ls, not just when it is used as a command. Just drop the -g option:
alias ls='ls -p --color'
In zsh you have global aliases when you use alias -g. A global alias is an alias that works not only on the beginning of your command but everywhere.
It is not what you want here!
But global aliases can be very powerful and useful. For instance:
alias -g L="| less" # to page the output with less
alias -g WL="| wc -l" # to have stats from wc
alias -g CP="| xclip -f -r" # to copy output into clipboard
alias -g NU="&> /dev/null" # to remove error and standard outputs
To use them:
ps aux L # expanded into: ps aux | less
ls -1 WL # expanded into: ls -1 | wc -l
date CP # expanded into: date | xclip -f -r
ls /foo2 /usr NU || echo okay # expanded into: ls /foo2 /usr &> /dev/null || ...

Change directory on remote server with zsh

I usually ssh into my aws account then immediately change directory to my working directory.
I am now using an alias in my .zshrc file for the ssh command. However , ideally, I'd like to ssh in then change directories automatically with my alias command. Cant figure out the cd part on the remote server. My alias looks something like this now:
alias aws="ssh -i ~/.ssh/mykeypair.pem ubuntu#11.11.111.11"
I think the preferred way would be creating ~/.zshrc or ~/.bashrc file on your remote host or appending to the end just:
cd your/working/directory/
Just tested and works fine for me
Other way would be changing your alias to something like:
alias aws="ssh -tt -i ~/.ssh/mykeypair.pem ubuntu#11.11.111.11 'cd your/working/directory/; bash'"
Additionally you can change bash for zsh if you want to use zsh as your shell on remote host.

bash sqlplus command not found

I am trying to install sqlplus on my mac following the tutorial here: https://tomeuwork.wordpress.com/2014/05/12/how-to-install-oracle-sqlplus-and-oracle-client-in-mac-os/comment-page-1/#comment-6
I have downloaded the two packages (basic and sqlplus) and created all the directories as it says, I moved the necessary files inside the directories.
I created and copied the tnsnames.ora file with the contents:
MYDB=
(DESCRIPTION=
(ADDRESS=
(PROTOCOL=TCP)
(HOST=*********)
(PORT=1521)
)
(CONNECT_DATA=
(SERVER=dedicated)
(SID=MYDB-SID)
) )
And i created the .bash_profile as it says in the tutorial.
But what im stuck on is making the sqlplus run.
typing in sqlplus returns command not found.
in the tutorial it says i should use $ sqlplus username/password#database
where do i get the username and database name from?, I haven't created one yet.
Thanks in advance.
According to your article, you should do the following:
$ vi ~/.bash_profile
Add the following line to the end of the file.
alias sqlplus=’rlwrap sqlplus’
Now reload the .bash_profile:
$ source ~/.bash_profile
Looks like you missed these steps.
You can try to execute:
$rlwrap sqlplus
According to the comments below you do not have sqlplus in the $PATH.
The value of $PATH looks wrong to me: duplicates, quotes.
Option 1
Execute:
export PATH=/Applications/‌​or‌​acle/product/instantclient_64/11.2.0.4.0/bin:/usr/local/bin:/usr/bin:/bin:/us‌​r/s‌​bin:/sbin
Then execute in the same console:
$ sqlplus (or $ rlwrap sqlplus)
It will set value only for the current shell. The main idea is to have full path to the sqlplus binary in the $PATH.
Option 2
Modify ~/.bash_profile.
To save as a permanent environment variable edit ~/.bash_profile. There are some details about setting PATH in the source article.
Top down troubleshooting approach
Look for binary - use type
[bbrandt] ~/ $ type sqlplus
sqlplus is aliased to `rlwrap sqlplus'
Where is my binary.. hidden behind an alias, let's unalias
[bbrandt] ~/ $ unalias sqlplus
[bbrandt] ~/ $ type sqlplus
sqlplus is /u01/app/oracle/product/11.2.0/xe/bin/sqlplus
Found it! What happens if I modify my binary search-path?
[bbrandt] ~/ $ echo $PATH
/u01/app/oracle/product/11.2.0/xe/bin:/home/bbrandt/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
[bbrandt] ~/ $ export PATH=/home/bbrandt/bin:/usr/lib64/ccache:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin
Now, where is my binary?
[bbrandt] ~/ $ type sqlplus
bash: type: sqlplus: not found
[bbrandt] ~/ $
This is where you are... look in your $PATH variable

alias in xargs sourcing tcsh

I am trying to run an xargs command that uses an alias. Searching came up with this
alias gojk 'stsq \!:1 | xargs -t -0 -I {} tcsh -c source ~/.tcshrc.user;myset {}'
but it returns
Bad ! arg selector
and variations will return
source: too few arguments.
tcsh still evaluates the ! character inside of quotes. You need to put a backslash before it.
I'd suggest you make the tcsh part a script, where you pass it an argument, and get this working. Then call the script using xargs.
Use the -m flag to tcsh to have it read your ~/.tcshrc on startup, as in
... | xargs -t0 -I {} tcsh -m -c "<alias> {}"