Run a command before and after running an interactive command - bash

I have a command say intr-cmd which opens an interactive console for web framework. But I need to run command cmd-a before and cmd-b after running the intr-cmd manually. These commands change some files for intr-cmd to run.
How can I code this in Bash such that I only have to run intr-cmd and these commands are run before and after it.
Edit:
Some explanation
intr-cmd opens an interactive console but it first reads a file of currently installed plugins to load them. But there is a plugin which is installed on production but is not working on the local environment and it is not necessary for my work. but the plugins file is committed into the git. so I have to comment on the plugin then run the intr-cmd and then uncomment that line in the file.
I want to automate this step so that it does not accidentally get committed to the git.

You can create a function intr-cmd, which replaces the general intr-cmd command, as explained here.
I should like like:
intr-cmd()
{
cmd-a
/path/intr-cmd
cmd-b
}
(Obviously you need to fill in the right path.)
I tried to flag your question as a duplicate, but as the link refers to another StackExchange forum, this wasn't allowed, hence this answer.

In your case, instead of changing intr-cmd each time you need it, you could create a git branch (possibly in a specific clone of your git repo) for your testing environment with a modified version of intr-cmd, and/or a modified version of the plugin list.

Related

enable certain commands in root level of a project without writing script nor manual setup for local machine

Currenly, if I want to run something like start in a project, let say /myproject I have to make a new bash file and name it like start in order to have some sort of command like ./start to work properly.
But I want to do is somehow I can add some sort of config file into the root folder to run all different kinds of command without ./ needed and simply start or anything else as I want to make, without having to create whole bunch of bash files.
Is there a way to setup it so if someone just pull a git repo down can just have it?
Assume that the git repo also contains package.json or maybe gradle.
However, I dont want to use npm run xxx or gradle xxx its just too much typing...
Sorry if I am asking too much for a setup lol

Error: Could not find or load main class org.apache.jackrabbit.vault.cli.VaultFsApp

We use VLT and GIT for our AEM site development.
I prefer the branch notifications and color coding etc. of GIT Bash,
to the standard output.
I use both from within ConEmu, and I have added Clink,
and that is somewhat better, but not as nice as GIT Bash.
Using the regular console I'm able to access VLT,
but when using the GIT Bash console, I get the following error.
"Error: Could not find or load main class org.apache.jackrabbit.vault.cli.VaultFsApp"
So it seems that there is a path that is not being found,
but running env|grep PATH shows the correct info.
Any help would be appreciated.
The shell's "PATH" isn't the problem.
You need to fix the Java "CLASSPATH".
You haven't specified your OS (Windows? Linux? Other?)
And I'm not sure exactly which program in the mix is using "org.apache.jackgrabbit.vault.cli". It certainly isn't Git BASH - it sounds like VLT is the guy who needs you to add Apache Jackrabbit to its Java CLASSPATH.
I fixed this in Windows 10 by running the command in cmd, rather than in git bash

Run Jenkins' Cygwin script as user

I have Jenkins running on Windows, and I have a build that works fine under CygWin bash from the CygWin terminal, so I now want to automate it. However, using this script:
#!C:\cygwin\bin\bash.exe
whoami
make
The system reports me as nt authority\system, not the ken that I get when using an interactive shell. Is there an easy way to persuade Jenkins or CygWin to run as me?
Most likely you are running jenkins with default installation. You have two options. First is mentioned in the comment. Change the "Service account" to be same as yours.
Second option is derived from best practices. Run the jenkins master on a system with backup etc. Configure slave node with your account credentials. Change the project configuration to build on the specific node.
(It is possible to run slave and master on same machine with different credentials - just in case you want to try out things)
The real problem I was having was not that the shell script was running as the wrong user, but that the shell script was not executing the default /etc/profile. So, the solution was simply:
#!C:\cygwin\bin\bash.exe -l
whoami
make
I was still nt authority\system, but now I had the correct environment set up and could run make successfully.
Note also that if I create a /home/system directory I can add .bash_profile, etc, to that directory to further customise the build environment.

Jekyll private deployment?

I have created jekyll site. Regarding the deployment I don't want to host on github pages. To host private domain I came know from documentation to copy the all files from _site folder. That's all wicked.
Question:
Each time I add new blog post, I am running cmd>jekyll build then I am copying newly created html to hosted domain. Is there any easy way to update without compiling each time ?
The reason, Why I am asking is because it will updated by non technical person
Thanks for the help!!
If you don't want to use GitHub Pages, AFAIK there's no other way than to compile your site each time you make a change.
But of course you can script/automate as much as possible.
That's what I do with my own blog as well. I'm hosting it on my own webspace instead of GitHub Pages, so I need to do these steps for each update:
Compile on local machine
Upload via FTP
I can do this with a single click (okay, a single double-click).
Note: I'm on Windows, so the following solution is for Windows.
But if you're using Linux/MacOS/whatever, of course you can use the tools given there to build something similar.
I'm using a batch file (the Windows equivalent to a shell script) to compile my site and then call WinSCP, a free command-line FTP client.
WinSCP allows me to store session configurations, so I saved the connection to my server there once.
Because of this, I didn't want to commit WinSCP to my (public) repository, so my script expects WinSCP in the parent folder.
The batch file looks like this:
call jekyll build
echo If the build succeeded, press RETURN to upload!
pause
set uploadpath=%~dp0\_site
%~dp0\..\winscp.com /script=build-upload.txt /xmllog=build-upload.log
pause
The first parameter in the WinSCP call (/script=build-upload.txt) specifies the script file which contains the actual WinSCP commands
This is in the script file:
option batch abort
option confirm off
open blog
synchronize remote -delete "%uploadpath%"
close
exit
Some explanations:
%~dp0 (in the batch file) is the folder where the current batch file is
The set uploadpath=... line (in the batch file) saves the complete path to the generated site into an environment variable
The open blog line (in the script file) opens a connection to the pre-saved session configuration (which I named blog)
The synchronize remote ... line (in the script file) uses the synchronize command to sync from the local folder (saved in %uploadpath%, the environment variable from step 2) to the server.
IMO this solution is suitable for non-technical persons as well.
If the technical person in your case doesn't know how to use source control, you could even script committing & pushing, too.
There are a number of options available which are mentioned in the documentation: http://jekyllrb.com/docs/deployment-methods/
If you are using Git, I would recommend the Git Post-Receive Hook approach. It simply builds the site after the new code is received:
GIT_REPO=$HOME/myrepo.git
TMP_GIT_CLONE=$HOME/tmp/myrepo
PUBLIC_WWW=/var/www/myrepo
git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
Since you mentioned that it will be updated by a non-technical person, you might try something like rack-jekyll to automatically rebuild when new files are FTP'd.

Set global environment variables inside Xcode build phase run script

I'm using Jenkins to do continuous integration builds. I have quite a few jobs that have much of the same configuration code. I'm in the midst of pulling this all out into a common script file that I'd like to run pre and post build.
I've been unable to figure out how to set some environment variables within that script, so that both the Xcode build command, and the Jenkins build can see them.
Does anyone know if this is possible?
It is not possible to do exactly what you ask. A process cannot change the environment variables of another process. The pre and post and actual build steps run in different processes.
But you can create a script that sets the common environment variables and share that script between all your builds.
The would first call your shell to execute the commands in the script and then call xcodebuild:
# Note the dot in the beginning of the next line. It is not a typo.
. set_environment.sh
xcodebuild myawesomeapp.xcodeproj
The script could look like this:
export VARIABLE1=value1
export VARIABLE2=value2
How exactly your jobs will share the script depends on your environment and use case. You can
place the script in some well-known location on the Jenkins host or
place the script in the version controlled source tree if all your jobs share the same repository or
place the script in a repository of its own and make a Jenkins build which archives the script as a build artifact. All the other jobs would then use Copy Artifact plugin to get a copy of the script from the artifacts of script job.
From Apple's Technical Q&A QA1067 it appears that if you create the file /Users/YOU/.MacOSX/environment.plist and populate it with your desired environment variables that all processes (launched by the user with the environment.plist file in their home dir) will pick up these environment variables. You may need to restart your computer (or just log out and back in) before a newly launched process will pick up the variables.
This article also claims that Xcode will also pass these variables to a build phase script. I have not tested it yet but next time I restart my MacBook I will let you know if it worked.
From http://developer.apple.com/library/mac/#/legacy/mac/library/qa/qa1067/_index.html
Q: How do I set environment for all processes launched by a specific
user?
A: It is actually a fairly simple process to set environment variables
for processes launched by a specific user.
There is a special environment file which loginwindow searches for
each time a user logs in. The environment file is:
~/.MacOSX/environment.plist (be careful it's case sensitive). Where
'~' is the home directory of the user we are interested in. You will
have to create the .MacOSX directory yourself using terminal (by
typing mkdir .MacOSX). You will also have to create the environment
file yourself. The environment file is actually in XML/plist format
(make sure to add the .plist extension to the end of the filename or
this won't work).

Resources