Creating symbolic links in AIX 6.1 server - unix

I'm trying to create sym-links using the following commands :
root:d2stud -> $ ln -s /usr/lib/libssl.a /opt/freeware/lib/libssl.a
ln: 0653-421 /opt/freeware/lib/libssl.a exists.
Specify -f to remove /opt/freeware/lib/libssl.a before linking.
(/stud/config/git_install)
root:d2stud -> $
root:d2stud -> $ ln -s /usr/lib/libcrypto.a /opt/freeware/lib/libcrypto.a
ln: 0653-421 /opt/freeware/lib/libcrypto.a exists.
Specify -f to remove /opt/freeware/lib/libcrypto.a before linking.
(/stud/config/git_install)
root:d2stud -> $
I did not get what I need to remove as specified by the error message.
Can anyone explain how I can resolve the error.

You can move it to the side:
mv <orig-path> <new-path>
i.e.
mv /opt/freeware/lib/libssl.a /opt/freeware/lib/libssl.a-orig
then if you want to go back like it was, move it back:
mv /opt/freeware/lib/libssl.a-orig /opt/freeware/lib/libssl.a.
If or when you want to go back, you would need to remove what you created at /opt/freeware/lib/libssl.a (such as the symlink you are trying to create).

Related

Unix script changing directory

I am in root directory, i am creating a script that will take me from root > Home > Logs and inside logs delete 3 log files.
Script will check if they exist, if YES it will delete it.
I am facing some syntax problems if you could help.
Thanks
My code:
#!/bin/sh
cd Home/Log
if [ -e error1.log ]
then
rm error1
fi
if [ -e error2.log ]
then
rm error1
fi
if [ -e error3.log ]
then
rm error1
fi
when i execute the file in root using ./delete here is what is am getting as errors:
$ ./delete
: No such file or directoryme/Log
./delete: line 14: syntax error near unexpected token `fi'
I am in root directory
When writing a script, it's almost always better not to assume things like that. If you know where the files are and it's not important that they're somewhere relative to what happens to be your current working directory, just name them.
Here are three ways you could accomplish what you want safely.
#!/bin/sh
dir=/Home/Log
rm -f ${dir}/error1.log ${dir}/error2.log ${dir}/error2.log
or
#!/bin/sh
dir=/Home/Log
rm -f ${dir}/error{1,2,3}.log
or
#!/bin/sh
set -e
cd /Home/Log && rm -f error1.log error2.log error2.log
For anything nontrivial, set -e is your friend. In your example, nothing happens later in the script. What you don't want is to keep going thinking you've changed directories, but haven't, and wind up scribbling somewhere you didn't intend. Many have lost much that way.

Can't get faketime to work with nginx

I'm trying to set up faking server time using libfaketime running nginx+php on ubuntu but no luck.
Here is what I've done:
1) Installed faketime:
$ wget http://www.code-wizards.com/projects/libfaketime/libfaketime-0.9.6.tar.gz
$ tar -xvzf libfaketime-0.9.6.tar.gz
$ cd libfaketime-0.9.6
$ make
$ sudo make install
$ echo "#2012-12-21 12:12:12" > /etc/faketimerc
2) added the following to my nginx.conf:
env LD_PRELOAD="/usr/local/lib/faketime/libfaketime.so.1";
3) Restarted nginx and php.
When I export LD_PRELOAD manually and then try date, it works, but when I do curl localhost or go to the website it gets the actual server date not the one from /etc/faketimerc
I've also tried setting LD_PRELOAD in :
/etc/environment
/etc/profile
/etc/profile.d/LD_PRELOAD.sh
/etc/default/nginx
Any ideas would be much appreciated.
Try set LD_PRELOAD for nginx (by root), not for user's shell:
LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1 /path/to/nginx
Try creating a txt file (eg: faketime.txt) and in it give the time you want
Eg: 2015-06-27 18:30:00
Then put the the following commands in the .config file
set.default.LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1
set.default.FAKETIME_TIMESTAMP_FILE=/home/Documents/faketime.txt

Run cd in script and stay in that directory - 'source' command not helping

Tried using the answer found here:
How to run 'cd' in shell script and stay there after script finishes?
When I add the 'source' command, the directory is still unchanged after script runs, regardless of whether I execute 'source ' or call the script using an alias coded in cshrc.
Any help is much appreciated!
As you can see below, make sure your call to cd is not executing within a subshell. If it is, this won't work, source or not.
Script with cd in subshell
#!/bin/bash
( cd /etc ) # thie exec's in a subshell
Output
$ pwd
/home/siegex
$ source ./cdafterend.sh && pwd
/home/siegex
Script with cd not in subshell
#!/bin/bash
cd /etc # no subshell here
Output
$ pwd
/home/siegex
$ source ./cdafterend.sh && pwd
/etc
It was necessary to remove "/bin/" from the cd command within this script, in order for the command to work as intended. Removing this removes the subshell issue for this script. Also, coding "$1" in the ls command was invalid in this context.

Unable to make symlinks effectively with target files of the same names

I have a list of dotFiles at my workarea. For example, .bashrc and .vimrc.
I want to make a symlinks from them to my Home such that their names are the same as in my workarea -folder.
My attempt in pseudo-code
ln workarea/.[a-zA-Z] ~/.*
The problem is to have a bijection from [a-zA-Z] to the files which occur in my Home.
How can you make symlinks with the target files of same name as the original files?
'man ln' says:
ln [OPTION]... TARGET... DIRECTORY (3rd form)
So you need to do something like:
$ ln -s workarea/.* ~/
The possible uses of ln to create symbolic link(s) are:
ln -s <source-file> [<target-file]>
ln -s <source-file> ... <target-dir>
When you type
ln -s workarea/.[a-zA-Z]* ~/.*
(I think you were missing a *) the shell will expand out workarea/.[a-zA-Z] and ~/.*, so (presuming that the your HOME directory contains the files .abc and .def) you would end up with
ln -s workarea/.bash_profile workarea/.bashrc ~/.abc ~/.def
which fits neither usage of ln.
To use the second usage of ln, you would use:
ln -s workarea/.[a-zA-Z]* ~/.

Is there a way to edit a symlink without deleting it first? [duplicate]

This question already has answers here:
Can you change what a symlink points to after it is created?
(8 answers)
Closed 5 years ago.
So I created a symlink:
ln -s /location/to/link linkname
Now I want to change the location that the symlink links to. How do I do that? is there a way to do it without deleting it first?
You could create the new link with a different name, then move it to replace the old link.
ln -s /location/to/link linkname
Later
ln -s /location/to/link2 newlink
mv newlink linkname
If newlink and linkname are on the same physical device the mv should be atomic.
Try ln -sf new_destination linkname.
Just change the symlink target:
# ln -sfT /path/to/new/target linkname
This is an instant, atomic change.
If the symlink targets are directories, you need to add the -T flag to the mv command, otherwise it moves the new symlink in to the target directory of the old symlink.
Example of atomically switching a website to a new version:
Original setup - website is stored in www1 directory, vhost pointing at www symlink:
ln -s www1 www
Browse to website, see old version.
Put new website files in new www2 directory.
Set up new symlink to new website:
ln -s www_new www2
Move www symlink to directory of new website:
mv -T www_new www
Browse to website, see new version immediately.
On OSX, the man page for ln says you can do it like this
ln -shf /location/to/link link name
From the man page:
The options are as follows:
-F If the target file already exists and is a directory, then remove it so that the link may occur. The -F
option should be used with either -f or -i options. If none is specified, -f is implied. The -F option is
a no-op unless -s option is specified.
-h If the target_file or target_dir is a symbolic link, do not follow it. This is most useful with the -f
option, to replace a symlink which may point to a directory.
-f If the target file already exists, then unlink it so that the link may occur. (The -f option overrides any
previous -i options.)
-i Cause ln to write a prompt to standard error if the target file exists. If the response from the standard
input begins with the character `y' or `Y', then unlink the target file so that the link may occur. Other-
wise, do not attempt the link. (The -i option overrides any previous -f options.)
-n Same as -h, for compatibility with other ln implementations.
-s Create a symbolic link.
-v Cause ln to be verbose, showing files as they are processed.
For directories, you want to do:
ln -sfT /location/to/new/target old_linkname
No. The symlink system call will return EEXIST if newpath already exists. You can only link from a new node in the filesystem. What's the requirement here? If you're worried about a race due to the non-atomicity of the unlink/symlink calls, then you might want to rethink the architecture a little to provide synchronization elsewhere. There have been some scary security bugs introduced by this kind of thing.
As others have mentioned, you basically have to delete the symlink first, either manually or by passing the -f flag to the ln utility.
Years ago, I had to make small edits to symlinks pretty frequently, so I wrote a simple readline-based utility (edln) to make this less annoying. In case anyone else finds it useful, I've put it online at https://github.com/jjlin/edln/.
edln will display the original symlink target; you can then use the arrow keys, or standard readline keystrokes (M-b, M-f, C-d, etc.) to move around and edit the target.
Chain the commands like this:
rm currentlink && ln -s /path/to/link currentlink
The first command removes the existing one and the 2nd immediately creates it again.
Just googled, found no good answer and had to solve myself:
ln -f -s -T `readlink SomeLibrary | sed 's/version.old/version.new/'` SomeLibrary
Editing by definition means not recreating from scratch but changing partly. Any answer requiring to memorize a path, maybe long or with weird symbols, is definitely bad.

Resources