I want the script to be able to find an application within the whole file system as the application is not always installed in the /Applications folder. I want to find it to remove it. Currently I have a script that looks in the users application folder and the general applications folder which is shared by all accounts. However, the application is sometimes stored in a different place.
currently the script checks if the process (the application) is running, if not then delete the application from the specified folder.
Is there any way to do a general sweep ?
#!/bin/bash
process="$4"
#check if abc is running
if pgrep $process >/dev/null 2>&1
then
echo $process is running
exit 1
else
echo $process is not running - remove all versions
#Remove ALL versions of Skype for Business.app
rm -rf $HOME/Applications/"Skype for Business.app"
rm -rf /Applications/"Skype for Business.app"
#Trigger the skype install policy
sudo jamf policy -event installSkype
echo "triggering install policy for Skype"
fi
Related
I'm trying to set up my system so that when a user logs in, a tmux session will automatically be created for them, and this session is restarted if it ever exits, and the session starts in the user's home directory. I would like this to work for any user, or any new user added to the system, without a static unit file for each user. I'm having trouble making this work in a generic way, because I need to specify User and WorkingDirectory in the unit file for the tmux session to be created for the correct user in the correct directory.
So far my unit file looks like the following:
/etc/systemd/system/tmux-session-service.service...
---------------------------------------------------
[Unit]
Description=Tmux Session Service
[Service]
Type=forking
User=my-user
WorkingDirectory=/home/my-user
ExecStart=/usr/bin/tmux new-session -s tmux-session-service -d
ExecStop=/usr/bin/tmux kill-session -t tmux-session-service
Restart=on-failure
[Install]
WantedBy=multi-user.target
When I install and enable this, everything works like I expect as long as I am logged is as my-user. However if I log in as another user, the tmux session isn't created with the right permissions or working directory for the new user.
I looked into template files, but I can't quite get things to work. I tried setting the target to default.target, and using the %u template directive, but that seems to just refer to the user running the service manager, which is root.
One option would be to run systemctl run tmux-session-service#new-user.service when new-user logs in. Then I could use %i in the User and WorkingDirectory directives in the unit file. But then I need some process that has systemctl permissions to kick that off on user login, and I can't think of a way to do that.
I'm running:
Arch Linux
tmux v3.1c
systemd v247
Under Ubuntu, I install the ....service file under:
/usr/lib/systemd/user/...
With the Debian packager, that is not automatic if you installed using the .service in the debian installation folder. Instead, you have to do it manually so it goes in the correct folder. So say you have a project defined like so:
tmux-session-service/debian/tmux-session-service.docs
tmux-session-service/debian/tmux-session-service.install
tmux-session-service/debian/tmux-session-service.service <-- wrong!
Then for each user I would enable the service like so:
# Make sure the target folder exists
mkdir -p /home/${USER}/.config/systemd/user/default.target.wants
# If you're root when doing that, you want to fix the ownership
# (for the group, you may need a different variable)
chown -R ${USER}:${USER} /home/${USER}/.config/systemd
# If already installed, remove the link before re-creating it
rm -f /home/${USER}/.config/systemd/user/default.target.wants/${SERVICE}.service
# Again, I do this as root, so I need to use special care to run the
# following command as $USER isntead
sudo -H -u ${USER} sh -c "ln -s /usr/lib/systemd/user/${SERVICE}.service /home/${USER}/.config/systemd/user/default.target.wants/${SERVICE}.service"
If you want (can) do it manually, then install the file under /usr/lib/systemd/user/... as mentioned above, and then use the enable option:
systemctl --user enable ${SERVICE}.service
The problem with this technique is that you need to log in as each user to order to enable your service.
I think there is a way to have a service auto-start for all users, but that I haven't found out how to make it work yet...
Could it be as simple as putting something in new user's .bashrc files (or in the /etc/profile file to get a system wide effect) that attaches to a tmux session called 'main' (this would create it if it doesn't already exist)?
That's what I have in mine, and it's as if tmux is just a built in feature of my terminal:
# Launch tmux
if command -v tmux>/dev/null; then
[[ ! $TERM =~ screen ]] && [ -z $TMUX ] && tmux new-session -A -s main
fi
in linux server someone copied the home directory to the different location . how to find which particular user who has carried the copy operation in the RHEL 6 server.
It depends on various things. If the sudo was used then the command should be logged in /var/log/secure.
You can execute this script to check command history of users on a server.
# the command that moved/copied home directory
# COMMAND=mv
COMMAND=cp
for user in $(ls /home/); do
# I assume that users use bash as their shell
sudo grep --with-filename ${COMMAND} /home/${user}/.bash_history 2>/dev/null
done
I have a linux box here that i've set up with a cifs shared folder to my windows computer. No issues there, it works exactly as intended. However, i thought about running some bash scripts using that same directory and it seems like it's not finding my root.
now=$(date +"%Y-%m-%d")
#or: `now=$(date +%s)` if you back up more than once a day
mkdir /__backup/"$now"
Doing this from the shared folder brings up that it cannot find directory
runningthese commands:
echo "$0"
dirname "$0"
shows the address as "."
Does anyone have any ideas on how to get this to run?
You are doing:
#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir "/__backup/$now"
So this only works if /__backup/ exists. Do:
#!/bin/bash
now=`date "+%Y-%m-%d"`
mkdir -p "/__backup/$now" # -p creates parent directories as needed (see man mkdir)
#Optional: change directory to the one you just created:
cd /__backup/$now
Of course, you will need root to make a directory in /, so you might want to check for that.
if [ `whoami` = "root" ]; then
# You are root...
else
echo "Error: Only root can do that."
exit 1
fi
You can avoid the whole problem of needing root if you create __backup in ~. You might also want to hide __backup by renaming it to .backup.
I'm facing an issue with creating init.d service. Following is my run.sh file which executes completely fine (As root user)
mvn install -DskipTests
mvn exec:java
But when I execute same file as service in init.d (service run start). I get
mvn command not found
Following is my start method
start() {
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > "$PIDFILE"
echo 'Service started' >&2
}
Link to complete script which i'm using
https://gist.githubusercontent.com/naholyr/4275302/raw/9df4ef3f4f2c294c9585f11d1c8593b62bdd52d3/service.sh
RUN AS value is set as root
When you run a command using sudo you are effectively running it as the superuser or root.
The reason that the root user is not finding your command is likely that the PATH environment variable for root does not include the directory where maven is located (quite evident as in the comments). Hence the reason for command not found error.
Add PATH to your script and that it includes /opt/integration/maven/apache-maven-3.3.9/bin. Since the init script won't share the PATH environment variable with the rest of the system (since it being run much ahead of the actual updates of $PATH in the .bash_profile) you need to set it directly on your script and make sure maven is in there, for example, add the below line to the init script in the beginning.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/opt/integration/maven/apache-maven-3.3.9/bin
I am using JBoss 7.1.1 application server with my java application in linux and have successfully been able to start JBoss during the processing phase of IZPack(processSpec.xml). I was getting "command not found" messages during the processing phase. I decided to get rid of all the comments and the messages went away. However, when I execute the uninstall, mkdir and ln -s -T appends a "?" at the end of the filename and link. Is this a bug? The rm -r successfuly removes the jboss script at /etc/init.d, but fails to remove the jboss-as.conf file at /etc/jboss-7.1.1.Final. I have jboss home at /usr/share. rm -r fails to remove /standalone and /modules. I get a popup during the uninstall stating administrative priveleges are required to remove /standalone and /modules.
All input is appreciated.
Glenn
rm(1) man page notes :
Otherwise, if a file is unwritable, standard input is a terminal, and the -f or --force option is not given, or the -i or
--interactive=always option is given, rm prompts the user for whether to remove the file. If the response is not affirma-tive, the file is skipped.
That appended ? after filename sounds like the prompt.
You're trying to remove files, that's readonly. rm -r is failing to remove things, probably because you don't own /standalone and /modules. Presumbably you needed "administrative privileges" to get things installed where they are in first place.