What is wrong my syntax for alias in zsh? - oh-my-zsh

I'm trying to create an alias to get all the containers in a pod in my k8 deployment. The alias works just fine in a Bash shell but in a Zsh shell, the sourcing fails with a no matches found error.
I tried the following aliases -
alias kgccsi='f(){ kubectl get pod $1 -o jsonpath='{.spec.containers[*].name}'; printf "\n"; unset -f f; }; f'
alias kgccsi='f(){ kubectl get pod $1 -o jsonpath='\{.spec.containers\[*\].name\}'; printf "\n"; unset -f f; }; f'
They are failing with a similar error -
.localAlias:9: no matches found: kgccsi=f(){ kubectl get pod $1 -o jsonpath={.spec.containers[*].name}; printf "\n"; unset -f f; }; f
I'm not used to shell scripting and any input will be appreciated.
Thanks.

Related

Cannot upload file to transfer.sh. Error: could no save metadata

Transfer.sh is a service that you can upload files by curl. I'm getting this error when I try to upload some file:
$ curl --upload-file file -s -w "\n" https://transfer.sh/
Could not save metadata
The service seems to be unstable.
You can use https://file.io
$ curl -F "file=#file" -s -w "\n" https://file.io {"success":true,"key":"Y7PDKv","link":"https://file.io/Y7PDKv","expiry":"14 days"}
With this bash function you can obtain the link
snd() {
curl --progress-bar -F "file=#$1" -s -w "\n" https://file.io | jq -r '.link'
}
alias snd=snd
How To use: snd filename.ext
Obtain: https://file.io/0uw5yYbkguc4
To parse the upload response, json, need to install "jq"

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 || ...

Openldap how to use RFC2307AIX schema which support aixAuxAccount objectClass

I'm setting up an Openldap system with two machines, include one Openldap Server (Redhat 6.4) and one Openldap Client (AIX 6.1)
Now I could create LDAP User and login in AIX machine with that account.
However, I want to use hostsdeniedlogin and hostsallowedlogin those are two attributes of objectClass aixauxaccount but my Openldap server doesn't have any Object like that.
I found an aix2307aix.schema on internet, but don't know how to use it.
rfc2307aix.schema
Beside that file, I also found: a file names nisSchema.ldif which have content in the following form:
dn:cn=schema
changetype: modify
replace: objectclasses
objectclasses: (
1.3.18.0.2.6.472
NAME 'aixAuxAccount'
DESC 'Auxiliary AIX user information objectclass, for use with posixaccount an
d shadowaccount objectclasses'
SUP top
AUXILIARY
MAY ( passwordChar $ adminGroupNames $ aIXDefaultMACLevel $ aIXFuncMode $ aIXi
sDCEExport $ aIXLowMACLevel $ aIXPromptMAC $ aIXScreens $ aIXUpperMACLevel $ aud
itClasses $ authMethod1 $ authMethod2 $ coreSizeLimit $ coreSizeLimitHard $ cPuS
ize $ cPuSizeHard $ dataSegSize $ dataSegSizeHard $ filePermMask $ fileSizeLimit
$ fileSizeLimitHard $ groupList $ groupSwitchUserAllowed $ hostLastLogin $ host
LastUnsuccessfulLogin $ hostsAllowedLogin $ hostsDeniedLogin $ isAdministrator $
isAccountEnabled $ isDaemon $ isLoginAllowed $ isRemoteAccessAllowed $ isSwitch
UserAllowed $ ixTimeLastLogin $ ixTimeLastUnsuccessfulLogin $ loginTimes $ maxFa
iledLogins $ maxLogin $ openFileLimit $ openFileLimitHard $ passwordCheckMethods
$ passwordDictFiles $ passwordExpireTime $ passwordHistSize $ passwordMaxRepeat
edChars $ passwordMinAlphaChars $ passwordMinDiffChars $ passwordMinLength $ pas
swordMinOtherChars $ physicalMemLimit $ physicalMemLimitHard $ roleList $ StackS
izeLimit $ StackSizeLimitHard $ SystemEnvironment $ terminalAccess $ terminalLas
tLogin $ terminalLastUnsuccessfulLogin $ timeExpiredLogout $ timeExpireLockout $
trustedPathStatus $ unsuccessfulLoginCount $ userEnvironment $ passwordFlags )
)
And I just found the way to add the rfc2307aix.schema file as the following link
how-to-add-a-new-schema-to-openldap
that schema seem to be added successfully, but I stuck with that nisSchema.ldif file found on AIX.
I attempted to use ldapadd, but not successful.
modifying entry "cn=schema,cn=config"
ldap_modify: Other (e.g., implementation specific) error (80)
Anyone know how to deal with this, please help!
I already had that "aixAuxAccount" ObjectClass. My AIX Client working fine now with 'hostsdeniedlogin' attribute. I had to clear the client cache and reconnect the Ldap Admin Tool to see the change. And don't need to use the nisSchema.ldif
For those, who dont know how to use the rfc2307aix.schema, please follow this thread:
how-to-add-a-new-schema-to-openldap
Thank you, for your attention and helps.

s3cmd invalidation choose distribution

I am trying to use s3cmd tool to invalidate my files,
it seems s3cmd automatically choose a distribution for me,
but I have more distributions from the same bucket, how can I choose distribution to invalidate ?
I have tried this :
s3cmd sync —cf-invalidate myfile cf://XXXXXXXXXX/mypath
but it does not work. I get this:
Invalid source/destination”
any idea?
thanks!
I believe you'd be looking to force an invalidation via the origin (i.e. your S3 bucket or similar) like so:
s3cmd --cf-invalidate _site/ s3://example-origin.com/
Here is my final conclusion:
after many many tries , the solution is very restrict.
follow this format:
s3cmd sync --cf-invalidate --acl-public --preserve --recursive ./[local_folder] s3://[my_bucket]/[remote_folder]/
when I run this command , the actual folder should be in command running folder
local file should have ./
remote folder should be end by /
I could not make s3cmd's invalidation work, so I used s3cmd to update the file and cloudfront-invalidator to do the invalidation. The script reads the aws authentication used by s3cmd for cloudfront-invalidator.
#!/bin/bash
if [ -z "$(which s3cmd)" ]; then
echo "s3cmd is not installed or is not on the PATH"
exit -1
fi
if [ -z "$(which cloudfront-invalidator)" ]; then
echo "cloudfront-invalidator is not installed or is not on the PATH"
echo "See https://github.com/reidiculous/cloudfront-invalidator"
echo "TL;DR: sudo gem install cloudfront-invalidator"
exit -1
fi
function awsKeyId {
awk -F '=' '{if (! ($0 ~ /^;/) && $0 ~ /aws_access_key_id/) print $2}' ~/.aws/config | tr -d ' '
}
function awsSecret {
awk -F '=' '{if (! ($0 ~ /^;/) && $0 ~ /aws_secret_access_key/) print $2}' ~/.aws/config | tr -d ' '
}
export file="stylesheets/main.css"
export distributionId=blahblah
export bucket=www.blahblah
s3cmd -P -m 'text/css' put public/$file s3://$bucket/$f
cloudfront-invalidator invalidate `awsKeyId` `awsSecret` $distributionId $file

Error submitting iOS .app using TestFlight API

I'm running the following script:
#!/bin/bash
archive=`./builds/myapp.ipa`
curl http://testflightapp.com/api/builds.json
-F file=$archive
-F api_token='xxxxxxxxxxxxxxxxxxxxxxxxxx'
-F team_token='xxxxxxxxxxxxxxxxxxxxxxxxxx'
-F notes='here comes the new app!'
-F notify=True
-F distribution_lists='MyFriends'
but I'm getting the error:
You must supply api_token, team_token, the file and notes (missing
file)
I'm actually copy/past-ing the script from the TestFlight website. What's wrong with that?
Please note that, as seen in the example given in the TestFlight API Documentation, you need to use the '#' character before the IPA file name.
You should try with:
#!/bin/bash
archive=`./builds/myapp.ipa`
curl http://testflightapp.com/api/builds.json \
-F file=#$archive \
-F api_token='xxxxxxxxxxxxxxxxxxxxxxxxxx' \
-F team_token='xxxxxxxxxxxxxxxxxxxxxxxxxx' \
-F notes='here comes the new app!' \
-F notify=True \
-F distribution_lists='MyFriends'